-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainClass.java
More file actions
29 lines (23 loc) · 816 Bytes
/
MainClass.java
File metadata and controls
29 lines (23 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MainClass extends JPanel {
Color colors[] = { Color.black, Color.blue, Color.cyan, Color.darkGray,
Color.gray, Color.green, Color.lightGray, Color.magenta, Color.orange,
Color.pink, Color.red, Color.white, Color.yellow };
public void paint(Graphics g) {
int deltax = 260 / colors.length;
for (int i = 0; i < colors.length; i++) {
g.setColor(colors[i]);
g.fillRect(i * deltax, 0, (i + 1) * deltax, 260);
}
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new MainClass());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);
}
}