My Rock Paper Scissors Game
i have a problem with my java code and it's really starting to bug me... i know.. i'm a new new new newbie and my java knowledge is at its minimum.. --_-- but i hope anyone can help me..
these are the errors that occur:
RRandomJava.ButtonHandler should be declared abstract; it does not define actionPerformed(java.awt.event.ActionEvent) in RandomJava.ButtonHandler <-- i've been getting lots of these lately and it's pissing me off >.>
possible loss of precision line 70
possible loss of precision line 71
possible loss of precision line 71
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
publicclass RandomJavaextends JFrame{
private JRadioButton rock, paper, scissor;
private ButtonGroup YourChoice;
private JButton click;
private JLabel l1, l2, l3;
private String ComChoice[] ={"ROCK","PAPER","SCISSORS"};
private JTextArea result;
public RandomJava(){
super ("Rock Paper Scissors Demo");
Container c = getContentPane();
c.setLayout(new FlowLayout());
l1 =new JLabel("Let's play Rock Paper Scissors!!");
l2 =new JLabel("Pick your choice");
l3 =new JLabel("Result ");
rock =new JRadioButton("ROCK",true);
paper =new JRadioButton("PAPER",false);
scissor =new JRadioButton("SCISSORS",false);
click =new JButton(" Enter ");
ButtonHandler h =new ButtonHandler();
click.addActionListener(h);
result =new JTextArea("Your choice:/t/tComputer's choice:/t/t/nResult:", 10, 5);
c.add(l1);
c.add(l2);
c.add(rock);
c.add(paper);
c.add(scissor);
c.add(click);
c.add(l3);
c.add(result);
YourChoice =new ButtonGroup();
YourChoice.add(rock);
YourChoice.add(paper);
YourChoice.add(scissor);
setSize(400, 350);
setVisible(true);
}
publicstaticvoid main(String args[])
{
RandomJava application =new RandomJava();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
privateclass ButtonHandlerimplements ActionListener{
publicvoid actionPerformed(Action event){
String put =" ";
int yours, coms;
if(rock.isSelected()){coms = Math.round((ComChoice.length - 1) * Math.random()); put +="Your choice: ROCK\t" +"Computer's Choice: " + coms; yours = 0;}
elseif(paper.isSelected()){coms = Math.round((ComChoice.length - 1) * Math.random()); put +="Your choice: PAPER\t" +"Computer's Choice: " + coms; yours = 1;}
elseif(scissor.isSelected()){coms = Math.round((ComChoice.length - 1) * Math.random()); put +="Your choice: SCISSORS\t" +"Computer's Choice: " + coms; yours = 2;}
if(yours == coms){put +="\nA DRAW!";}
elseif(yours > coms){put +="\nYOU WON!";}
elseif(coms > yours){put +="\nYOU LOST!";}
result.setText(put);
}
}
}
Message was edited by:
kageNOhikari

