-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicEventInSwing.java
More file actions
56 lines (54 loc) · 1.22 KB
/
BasicEventInSwing.java
File metadata and controls
56 lines (54 loc) · 1.22 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
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class BasicEventInSwing extends JFrame implements ActionListener
{
JButton b1,b2,b3,b4;
JPanel p;
public BasicEventInSwing()
{
getContentPane().setLayout(new FlowLayout());
p=new JPanel();
getContentPane().add(p);
p.setBackground(Color.BLUE);
b1=new JButton("YELLOW");
b2=new JButton("PINK");
b3=new JButton("ORANGE");
b4=new JButton("Quit");
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
getContentPane().setBackground(Color.GREEN);
}
public void actionPerformed(ActionEvent e)
{
String str=e.getActionCommand();
if(str.equals("YELLOW"))
{
getContentPane().setBackground(Color.YELLOW);
}
else if(str.equals("PINK"))
{
getContentPane().setBackground(Color.PINK);
}
else if(str.equals("ORANGE"))
{
getContentPane().setBackground(Color.ORANGE);
}
else if(str.equals("Quit"))
{
System.exit(0);
}
}
public static void main(String args[])
{
BasicEventInSwing b=new BasicEventInSwing();
b.setSize(500,500);
b.setVisible(true);
}
}