-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTraffic.java
More file actions
69 lines (67 loc) · 1.34 KB
/
Traffic.java
File metadata and controls
69 lines (67 loc) · 1.34 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
import java.awt.*;
import java.awt.event.*;
class Traffic extends Frame implements ItemListener
{
CheckboxGroup g;
Checkbox c1,c2,c3;
Label h,l;
Font f;
Traffic()
{
g=new CheckboxGroup();
c1=new Checkbox("Red",g,false);
c2=new Checkbox("Yellow",g,false);
c3=new Checkbox("Green",g,false);
h=new Label("Traffic Light Simulator");
l=new Label(" ",Label.CENTER);
f=new Font("Arial",Font.BOLD,24);
h.setFont(f);
add(h);
add(c1);
add(c2);
add(c3);
add(l);
setLayout(null);
h.setBounds(200,20,350,60);
l.setBounds(220,120,180,60);
c1.setBounds(50,220,100,60);
c2.setBounds(50,290,100,60);
c3.setBounds(50,360,100,60);
c1.addItemListener(this);
c2.addItemListener(this);
c3.addItemListener(this);
setSize(600,600);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
}
public void itemStateChanged(ItemEvent e)
{
Font f=new Font("Arial",Font.BOLD,24);
l.setFont(f);
if(e.getSource()==c1)
{
l.setForeground(Color.RED);
l.setText("Stop");
}
else if(e.getSource()==c2)
{
l.setForeground(Color.YELLOW);
l.setText("Ready");
}
else
{
l.setForeground(Color.GREEN);
l.setText("Go");
}
}
public static void main(String args[])
{
new Traffic();
}
}