package graphtest; import javax.swing.*; import java.awt.*; import java.awt.image.MemoryImageSource; import static java.lang.Math.max; public class Panel extends JPanel { private Image img; @Override // переозначення методу малювання public void paintComponent (Graphics g) { super.paintComponent(g); g.setColor(Color.yellow); Graphics2D g2 = (Graphics2D) g; int w = getSize().width, h = getSize().height; int [] pix = new int [w*h]; for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { int red = max(0,255 -(x + y)/2); int blue = max(0,255 -(x + (h-y-1))/2); int green = max(0,255 -((w-x-1) + y)/2); pix [w*y+x] = (255 << 24) | (red << 16) | (green << 8) | (blue << 0); } } if (img == null) img = createImage (new MemoryImageSource (w, h, pix, 0, w)); g2.drawImage (img, 0, 0, this); } }