import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame{
ImageIcon icon1 = new ImageIcon("보자기.jpg");
ImageIcon icon2 = new ImageIcon("가위.jpg");
ImageIcon icon3 = new ImageIcon("바위.jpg");
ImageIcon icon4 = new ImageIcon("웃는 얼굴.jpg");
ImageIcon icon5 = new ImageIcon("안웃는 얼굴.jpg");
JButton[] jb = new JButton[3];
ImageIcon[] names = {icon1, icon2, icon3};
JLabel la1=new JLabel(icon4);
JLabel la2=new JLabel(icon5);
public Main() {
JPanel p_up = new JPanel();
Container c= getContentPane();
c.setLayout(new BorderLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
for(int i=0;i<3;i++) {
jb[i]=new JButton(names[i]);
c.add(jb[i]);
p_up.add(jb[i]);
jb[i].addMouseListener(new MyMouseListener());
}
p_up.setBackground(Color.DARK_GRAY);
c.add(p_up, BorderLayout.NORTH);
JLabel la3=new JLabel("You");
JLabel la4=new JLabel("Computer");
JPanel p_dw = new JPanel();
p_dw.setBackground(Color.yellow);
p_dw.add(la1);
p_dw.add(la3);
p_dw.add(la2);
p_dw.add(la4);
c.add(p_dw, BorderLayout.CENTER);
setSize(1000,650);
setVisible(true);
}
private class MyMouseListener extends MouseAdapter{
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
JButton jb = (JButton)e.getSource(); // 눌린 버튼을 jb라고 부를게
if(jb.getIcon().equals(icon1)) {
la1.setIcon(icon1);
}
else if(jb.getIcon().equals(icon2)){
la1.setIcon(icon2);
}
else {
la1.setIcon(icon3);
}
}
}
public static void main(String[] args) {
new Main();
}
}