-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrayRows.java
More file actions
68 lines (45 loc) · 1.2 KB
/
Copy pathGrayRows.java
File metadata and controls
68 lines (45 loc) · 1.2 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
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 GrayRows extends Frame {
public GrayRows() {
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;
int n_rows = 10;
float color_step = 1.0f/n_rows;
int x = 0;
int y = 0;
int y_step = this.getHeight()/n_rows;
int height = y_step;
for(int i = 0; i < n_rows; i++) {
float val = (n_rows - 1 - i)*color_step;
Color col = new Color(val, val, val);
g2d.setColor(col);
g2d.fillRect(x, y, this.getWidth(), height);
y += y_step;
}
}
public static void main(String[] argv)
{
GrayRows f = new GrayRows();
//f.setTitle("The first Java 2D program");
f.setTitle("Four Colors");
f.setSize(400, 400);
f.setVisible(true);
}
}