-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrafficnw.java
69 lines (61 loc) · 1.6 KB
/
trafficnw.java
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.*;
import javax.swing.*;
class traffic implements ActionListener
{
JFrame jf;
JLabel jl;
JRadioButton jrbred,jrbyellow,jrbgreen;
ButtonGroup btngroup;
traffic()
{
jf=new JFrame("traffic light");
jl=new JLabel("SELECT LIGHT");
jrbred=new JRadioButton("Red");
jrbyellow=new JRadioButton("Yellow");
jrbgreen=new JRadioButton("Green");
FlowLayout f=new FlowLayout();
jf.setLayout(f);
jf.setSize(500,500);
jf.setVisible(true);
jrbred.setForeground(Color.RED);
jrbyellow.setForeground(Color.YELLOW);
jrbgreen.setForeground(Color.GREEN);
btngroup = new ButtonGroup();
btngroup.add(jrbred);
btngroup.add(jrbyellow);
btngroup.add(jrbgreen);
jf.add(jrbred);
jf.add(jrbyellow);
jf.add(jrbgreen);
jf.add(jl);
jrbred.addActionListener(this);
jrbyellow.addActionListener(this);
jrbgreen.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String s1=ae.getActionCommand();
if(s1.equals("Red"))
{
jl.setForeground(Color.RED);
jl.setText("STOP");
}
else if(s1.equals("Yellow"))
{
jl.setForeground(Color.YELLOW);
jl.setText("READY");
}
else if(s1.equals("Green"))
{
jl.setForeground(Color.GREEN);
jl.setText("GO");
}
}
}
class trafficnw
{
public static void main(String arg[]) {
new traffic();
}
}