-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathColorFrame.java
More file actions
104 lines (83 loc) · 2.48 KB
/
ColorFrame.java
File metadata and controls
104 lines (83 loc) · 2.48 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//GUI program to change the background colors when you click on buttons.
package src.college.understanding_GUI;
import java.awt.*;
import java.awt.event.*;
class ColorFrame extends Frame implements ActionListener {
Button r, g, b, y;
ColorFrame(String s) {
super(s);
}
void createWindow() {
r = new Button("RED");
g = new Button("GREEN");
b = new Button("BLUE");
y = new Button("YELLOW");
setLayout(new FlowLayout());
add(r);
add(g);
add(b);
add(y);
setSize(200, 400);
setVisible(true);
r.addActionListener(this);
g.addActionListener(this);
b.addActionListener(this);
y.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == r)
setBackground(Color.red);
if (e.getSource() == g)
setBackground(Color.green);
if (e.getSource() == b)
setBackground(Color.blue);
if (e.getSource() == y)
setBackground(Color.yellow);
}
public static void main(String[] args) {
ColorFrame c = new ColorFrame("Color Frame");
c.createWindow();
}
}
class Watch extends Frame implements ActionListener {
Watch(String str){
super(str);
}
Button red, blue, green, yellow;
void createWindow(){
red = new Button("RED");
blue = new Button("BLUE");
green = new Button("GREEN");
yellow = new Button("YELLOW");
red.addActionListener(this);
blue.addActionListener(this);
green.addActionListener(this);
yellow.addActionListener(this);
red.setForeground(Color.RED);
blue.setForeground(Color.BLUE);
green.setForeground(Color.GREEN);
yellow.setForeground(Color.YELLOW);
add(red); add(green); add(blue); add(yellow);
setLayout(new FlowLayout());
setSize(300, 400);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == red){
setBackground(Color.RED);
}
if(e.getSource() == blue){
setBackground(Color.BLUE);
}
if(e.getSource() == green){
setBackground(Color.GREEN);
}
if(e.getSource() == yellow){
setBackground(Color.YELLOW);
}
}
public static void main(String[] args) {
Watch w1 = new Watch("Wathes request");
w1.createWindow();
}
}