-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonExam.java
More file actions
52 lines (34 loc) · 986 Bytes
/
ButtonExam.java
File metadata and controls
52 lines (34 loc) · 986 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package eventExam;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class ButtonExam extends JFrame implements ActionListener{
JPanel p = new JPanel();
JButton btn1 = new JButton("주황색");
JButton btn2 = new JButton("파란색");
ButtonExam(){
add(p);
p.add(btn1);
p.add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
setTitle("패널 색 바꾸기");
setSize(700, 400);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new ButtonExam();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == btn1) {
p.setBackground(Color.orange);
}else if(e.getSource() == btn2) {
p.setBackground(Color.blue);
}
}
}