import javax.swing.*;
import javax.swing.border.Border;
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("보자기.png");
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);
JLabel la5=new JLabel("Who Is Winner");
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_sw=new JPanel();
p_sw.setBackground(Color.yellow);
JPanel p_dw = new JPanel();
la5.setForeground(Color.red);
la5.setFont(new Font("Arial",Font.BOLD,80));
p_dw.setBackground(Color.yellow);
p_dw.add(la1);
p_dw.add(la3);
p_dw.add(la2);
p_dw.add(la4);
p_sw.add(la5);
c.add(p_dw, BorderLayout.CENTER);
c.add(p_sw, BorderLayout.SOUTH);
setSize(1780,950);
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);
}
int awd=(int)(Math.random()*3);
if(awd==0) {
la2.setIcon(icon1);
}
else if(awd==1) {
la2.setIcon(icon2);
}
else {
la2.setIcon(icon3);
}
if(la2.getIcon().equals(la1.getIcon())) {
la5.setText("Try Again");
}
else if(la1.getIcon().equals(icon1)) {
if(la2.getIcon().equals(icon2)) la5.setText("You Lose");
else if(la2.getIcon().equals(icon3)) la5.setText("You Win");
}
else if(la1.getIcon().equals(icon2)&&la2.getIcon().equals(icon1)) {
la5.setText("You Win");
}
else if(la1.getIcon().equals(icon2)&&la2.getIcon().equals(icon3)) {
la5.setText("You Lose");
}
else if(la1.getIcon().equals(icon3)&&la2.getIcon().equals(icon1)) {
la5.setText("You Lose");
}
else if(la1.getIcon().equals(icon3)&&la2.getIcon().equals(icon2)) {
la5.setText("You Win");
}
}
}
public static void main(String[] args) {
new Main();
}
}