-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSignals.java
55 lines (46 loc) · 1.4 KB
/
Signals.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
import java.awt.*;
import java.awt.event.*;
public class Signals extends Frame implements ActionListener{
TextField tf;
Button b1,b2,b3;
public Signals(){
tf= new TextField();
tf.setBounds(50,50,150,20);
b1=new Button("Stop!");
b2=new Button("Ready!!");
b3= new Button("Go!!!");
b1.setBounds(100,100,75,50);
b2.setBounds(100,200,75,50);
b3.setBounds(100,300,75,50);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
tf.setEditable(false);
add(tf);
add(b1);
add(b2);
add(b3);
setSize(500,500);
setLayout(null);
setVisible(true);
}
// e.getSource() will return the object that is making
//Action
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
tf.setForeground(Color.red);
tf.setText("Stop!");
}
else if(e.getSource()==b2){
tf.setForeground(Color.orange);
tf.setText("Ready!!");
}
else if(e.getSource()==b3){
tf.setForeground(Color.green);
tf.setText("Go!!!");
}
}
public static void main(String []args){
new Signals();
}
}