-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrafficDrawer.java
More file actions
53 lines (42 loc) · 1.31 KB
/
TrafficDrawer.java
File metadata and controls
53 lines (42 loc) · 1.31 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
package traffictester;
import javax.swing.JFrame;
import java.awt.Graphics;
import java.awt.Color;
public class TrafficDrawer extends JFrame {
private final int PLUS = 1;
private final int MINUS = 2;
private int[][] array;
private int size;
//Constructor of Traffic Drawer class
public TrafficDrawer(int[][] array, int size)
{
setSize(5 * size, 5 * size);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
this.array = array;
this.size = size;
}
public void paint(Graphics g)
{
//go through array
for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++)
{
if (array[i][j] == PLUS)
{
g.setColor(Color.RED);
g.fillRect(5 * j, 5 * i, 5, 5);
}
else if (array[i][j] == MINUS)
{
g.setColor(Color.GREEN);
g.fillRect(5 * j, 5 * i, 5, 5);
}
else
{
g.setColor(Color.BLACK);
g.fillRect(5 * j, 5 * i, 5, 5);
}
}
}
}