import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame
{
Container c = getContentPane();
JLabel la = new JLabel();
JLabel la1 = new JLabel("me");
JLabel la2 = new JLabel("com");
JButton b1 = new JButton(new ImageIcon("C:\\Users\\user\\Desktop\\images\\scissors.jpg"));
JButton b2 = new JButton(new ImageIcon("C:\\Users\\user\\Desktop\\images\\rock.jpg"));
JButton b3 = new JButton(new ImageIcon("C:\\Users\\user\\Desktop\\images\\paper.jpg"));
JLabel bm = new JLabel();
JLabel bc = new JLabel();
public Main()
{
setTitle("Image Gallery Practice Frame");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyActionListener ac = new MyActionListener();
c.setLayout(new FlowLayout());
b1.addActionListener(ac);
b2.addActionListener(ac);
b3.addActionListener(ac);
c.add(b1);
c.add(b2);
c.add(b3);
c.add(bm);
c.add(la1);
c.add(bc);
c.add(la2);
setSize(1000,1000);
setVisible(true);
}
class MyActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e) {
JButton bu = (JButton)e.getSource();
int ran = (int)(Math.random()*3);
if(ran==0)
{
bc.setIcon(new ImageIcon("C:\\Users\\user\\Desktop\\images\\scissors.jpg"));
}
else if(ran==1)
{
bc.setIcon(new ImageIcon("C:\\Users\\user\\Desktop\\images\\rock.jpg"));
}
else
{
bc.setIcon(new ImageIcon("C:\\Users\\user\\Desktop\\images\\paper.jpg"));
}
if(bu==b1)
{
}
//if(이겼을때)
//{
// la.setText("win");
//}
}
}
public static void main(String[] args) {
new Main();
}
}