import javax.swing.*;
import java.awt.*;
public class Main extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
int c = (i + j) * 255 / 6;
g.setColor(new Color(c, c, c));
g.fillRect(i * getWidth() / 4,
j * getHeight() / 4,
getWidth() / 4,
getHeight() / 4);
}
}
}
public static void main(String[] args) {
JFrame frame = new JFrame("Градиент");
Main panel = new Main();
frame.add(panel);
frame.setSize(400, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}