-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonFrame.java
More file actions
37 lines (34 loc) · 846 Bytes
/
ButtonFrame.java
File metadata and controls
37 lines (34 loc) · 846 Bytes
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
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
public class ButtonFrame extends JFrame{
private JPanel panel;
private JButton button;
ButtonFrame(){
setSize(200,100);
panel = new JPanel();
button = new JButton();
ButtonListener a = new ButtonListener(Color.RED);
button.addActionListener(a);
panel.add(button);
add(panel);
}
private class ButtonListener implements ActionListener{
private Color backgroundColor;
ButtonListener(Color c){
backgroundColor = c;
}
public void actionPerformed(ActionEvent e){
panel.setBackground(backgroundColor);
}
}
}
class ButtonFrameTest{
public static void main(String[] args){
ButtonFrame a = new ButtonFrame();
a.setVisible(true);
}
}