-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColourWindow.java
67 lines (67 loc) · 1.62 KB
/
ColourWindow.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
import java.awt.*;
import java.awt.event.*;
public class ColourWindow extends Frame implements ActionListener
{
Button red,green,blue,close;
ColourWindow()
{
setLayout(new FlowLayout());
setSize(400,400);
setTitle("Buttons in Action");
setVisible(true);
red=new Button("Red");
green=new Button("Green");
blue=new Button("Blue");
close=new Button("Close");
add(red);
add(green);
add(blue);
add(close);
red.addActionListener(this);
green.addActionListener(this);
blue.addActionListener(this);
close.addActionListener(this);
Windowadapter w=new Windowadapter(this);
addWindowListener(w);
}
class Windowadapter extends WindowAdapter
{
ColourWindow colourwindow;
Windowadapter(ColourWindow colourwindow)
{
this.colourwindow=colourwindow;
}
public void windowClosing(WindowEvent we)
{
colourwindow.setVisible(false);
}
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
if(str.equals("Red"))
{
setBackground(Color.red);
close.setForeground(Color.red);
}
else if(str.equals("Green"))
{
setBackground(Color.green);
close.setForeground(Color.green);
}
else if(str.equals("Blue"))
{
setBackground(Color.blue);
close.setForeground(Color.blue);
}
else
{
setBackground(Color.white);
close.setForeground(Color.black);
}
}
public static void main(String args[])
{
ColourWindow A=new ColourWindow();
}
}