RPS/Screen.java

88 lines
2.8 KiB
Java

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Screen {
static boolean rock = false;
static boolean scissors = false;
static boolean paper = false;
public static void main(String[] args) {
JFrame frame = new JFrame("rock paper scissors");
frame.setSize(300,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton rockbutton = new JButton("rock");
JButton paperbutton = new JButton("paper");
JButton scissorsbutton = new JButton("scissors");
JPanel panel = new JPanel();
JLabel Label = new JLabel("play");
panel.add(rockbutton);
panel.add(paperbutton);
panel.add(scissorsbutton);
panel.add(Label);
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
rockbutton.setAlignmentX(JButton.CENTER_ALIGNMENT);
paperbutton.setAlignmentX(JButton.CENTER_ALIGNMENT);
scissorsbutton.setAlignmentX(JButton.CENTER_ALIGNMENT);
Label.setAlignmentX(JLabel.CENTER_ALIGNMENT);
rockbutton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
rock = true;
if(rock == true) {
scissors = false;
paper = false;
Thecomputer.generate(args);
System.out.println("rock is true");
if(Thecomputer.aipaper == true){
Label.setText("paper, you lose");
};
if(Thecomputer.airock == true){
Label.setText("rock, tie");
};
if(Thecomputer.aiscissors == true){
Label.setText("scissors, you win");
};
};
}
});
paperbutton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
paper = true;
if(paper == true) {
rock = false;
scissors = false;
System.out.println("paper is true");
};
}
});
scissorsbutton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
scissors = true;
if(scissors == true) {
paper = false;
scissors = false;
System.out.println("Scirrors is true");
};
}
});
frame.add(panel);
frame.setVisible(true);
}
}