-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrafficDrawer.java
More file actions
61 lines (50 loc) · 1.43 KB
/
Copy pathTrafficDrawer.java
File metadata and controls
61 lines (50 loc) · 1.43 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
import javax.swing.JFrame;
import java.awt.Graphics;
import java.awt.Color;
//Program draws array of two types of vehicles
public class TrafficDrawer extends JFrame
{
private final int PLUS = 1; //type one vehicle
private final int MINUS = 2; //type two vehicle
private int[][] array; //array of vehicles
private int size; //size of array
/*******************************************************************/
//constructor of trafficDrawer class
public TrafficDrawer(int[][] array, int size)
{
setSize(5*size, 5*size); //set window size to 5*size
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//standard window settings
setVisible(true);
this.array = array; //set array to be drawn
this.size = size; //set array size
}
/*******************************************************************/
//method paints window
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) //draw type one vehicle
{
g.setColor(Color.RED);
g.fillRect(5*j, 5*i, 5, 5);
}
else if (array[i][j] == MINUS) //draw type two vehicle
{
g.setColor(Color.GREEN);
g.fillRect(5*j, 5*i, 5, 5);
}
else
{
g.setColor(Color.BLACK); //draw empty location
g.fillRect(5*j, 5*i, 5, 5);
}
}
}
}
/*******************************************************************/
}