-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJLabelTest1.java
More file actions
39 lines (38 loc) · 1.03 KB
/
Copy pathJLabelTest1.java
File metadata and controls
39 lines (38 loc) · 1.03 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
package programing;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class JLabel1 extends JFrame implements ActionListener {
private JLabel result = new JLabel();
public ImageIcon i1,i2;
public JLabel1() {
i1 = new ImageIcon(getClass().getResource("apple.jpg"));
i2 = new ImageIcon(getClass().getResource("pear.jpg"));
JButton apple = new JButton("사과");
JButton pear = new JButton("배");
Container ct = getContentPane();
ct.setLayout(new FlowLayout());
ct.add(apple);
ct.add(pear);
ct.add(result);
apple.addActionListener(this);
pear.addActionListener(this);
setTitle("JLabel Test1");
setSize(300,250);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if(ae.getActionCommand()=="사과") {
result.setText("맛있는 사과입니다");
result.setIcon(i1);
}else {
result.setText("맛있는 배입니다");
result.setIcon(i2);
}
}
}
public class JLabelTest1 {
public static void main(String[] args) {
new JLabel1();
}
}