It looks like you're using an Ad Blocker.
Please white-list or disable AboveTopSecret.com in your ad-blocking tool.
Thank you.
Some features of ATS will be disabled while you continue to use an ad-blocker.
import javax.swing.JFrame;
public class GameMain [
public static void main(String[] args) [
JFrame frame = new JFrame ("Rock Paper Scissors");
GamePanel panel = new GamePanel();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
]
]
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class GamePanel extends JPanel[
private JLabel userLabel, computerLabel, resultLabel, winLabel, tieLabel, loseLabel;
private JButton rockButton, paperButton, scissorsButton;
private int winInt, tieInt, loseInt;
public GamePanel()[
winInt = 0;
tieInt= 0;
loseInt = 0;
rockButton = new JButton("Rock");
paperButton = new JButton("Paper");
scissorsButton = new JButton("Scissors");
//action listeners
rockButton.addActionListener(new ButtonListener());
paperButton.addActionListener(new ButtonListener());
scissorsButton.addActionListener(new ButtonListener());
add(rockButton);
add(paperButton);
add(scissorsButton);
setBackground(Color.BLUE.darker());
setPreferredSize(new Dimension(300, 150));
]
private class ButtonListener implements ActionListener [
public void actionPerformed(ActionEvent ae)[
Object userSource = ae.getSource();
Object computerSource = ae.getSource();
if (userSource == rockButton && computerSource == scissorsButton)[
winInt++;
]else if (userSource == paperButton && computerSource == rockButton)[
winInt++;
]else if (userSource == scissorsButton && computerSource == paperButton)[
winInt++;
]else if (computerSource == rockButton && userSource == scissorsButton)[
loseInt++;
]else if (computerSource == paperButton && userSource == rockButton)[
loseInt++;
]else if (computerSource == scissorsButton && userSource == paperButton)[
loseInt++;
]else[
tieInt++;
]
]
]
]