-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchangebackground.java
More file actions
60 lines (48 loc) · 1.54 KB
/
changebackground.java
File metadata and controls
60 lines (48 loc) · 1.54 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
import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
public class changebackground extends Frame implements ActionListener{
Button b1, b2, b3;
public changebackground(){
this.setVisible(true);
this.setSize(500,500);
this.addWindowListener(new windowadapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
this.setLayout(new FlowLayout());
b1= new Button("RED");
b2= new Button("GREEN");
b3= new Button("YELLOW");
b1.setBackground(Color.RED);
b2.setBackground(Color.GREEN);
b2.setBackground(Color.YELLOW);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
this.add(b1);
this.add(b2);
this.add(b3);
}
@Override
public void actionPerformed(ActionEvent e) {
String label= e.getActionCommand();
if(label.equals("RED")){
this.setBackground(Color.RED);
}
if(label.equals("GREEN")){
this.setBackground(Color.GREEN);
}
if(label.equals("YELLOW")){
this.setBackground(Color.YELLOW);
}
}
public static void main(String[] args) {
changebackground cb= new changebackground();
}
}