-
Notifications
You must be signed in to change notification settings - Fork 0
/
Swing6_4.java
52 lines (43 loc) · 1.5 KB
/
Swing6_4.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
import com.sun.source.tree.NewArrayTree;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Swing6_4 {
public static Container c;
public static void main(String[] args) {
JFrame frame = new JFrame("Action Demo");
frame.setBounds(10,20,1000,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
c= frame.getContentPane();
c.setLayout(null);
JButton red = new JButton("RED");
JButton yellow = new JButton("YELLOW");
JButton green = new JButton("GREEN");
red.setBounds(20,100,100,25);
yellow.setBounds(180,100,100,25);
green.setBounds(340,100,100,25);
red.addActionListener(new Red());
yellow.addActionListener(new Yellow());
green.addActionListener(new Green());
c.add(red);
c.add(yellow);
c.add(green);
}
static class Red implements ActionListener{
public void actionPerformed(ActionEvent e){
Swing6_4.c.setBackground(Color.RED);
}
}
static class Yellow implements ActionListener{
public void actionPerformed(ActionEvent e){
Swing6_4.c.setBackground(Color.YELLOW);
}
}
static class Green implements ActionListener{
public void actionPerformed(ActionEvent e){
Swing6_4.c.setBackground(Color.GREEN);
}
}
}