-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFourColors.java
More file actions
72 lines (48 loc) · 1.27 KB
/
Copy pathFourColors.java
File metadata and controls
72 lines (48 loc) · 1.27 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package lab_5_exercises;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class FourColors extends Frame {
public FourColors() {
addWindowListener(new MyFinishWindow());
// TODO Auto-generated constructor stub
}
public class MyFinishWindow extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
public void paint(Graphics g)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.RED);
int x = 0;
int y = 0;
int width = this.getWidth()/2;
int height = this.getHeight()/2;
g2d.fillRect(x, y, width, height);
x += width;
g2d.setColor(Color.GREEN);
g2d.fillRect(x, y, width, height);
x = 0;
y += height;
g2d.setColor(Color.BLUE);
g2d.fillRect(x, y, width, height);
x += width;
g2d.setColor(Color.BLACK);
g2d.fillRect(x, y, width, height);
}
public static void main(String[] argv)
{
FourColors f = new FourColors();
//f.setTitle("The first Java 2D program");
f.setTitle("Four Colors");
f.setSize(400, 400);
f.setVisible(true);
}
}