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

[5845 byte] By [kageNOhikaria] at [2007-11-26 19:10:21]
# 1

Read the error messages.

RandomJava.java:64: RandomJava.ButtonHandler is not abstract and does not overri

de abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event

.ActionListener

private class ButtonHandler implements ActionListener{

So ActionListener wants a method called actionPerformed, and takes a ActionEvent.

But look at the code. actionPerformed(Action event)

RandomJava.java:70: possible loss of precision

found: long

required: int

if(rock.isSelected()) {coms = Math.round((ComChoice.leng

th - 1) * Math.random()); put += "Your choice: ROCK\t" + "Computer's Choice: " +

coms; yours = 0; }

[url=http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Math.html#round(double)]Math.round(double)[/url] returns a long, you are attempting to assign that to a "int". You need to cast.

mlka at 2007-7-9 21:06:15 > top of Java-index,Java Essentials,New To Java...
# 2
so that's where I got wrong!Thanks mlk... you're such a big help for this little minded newbie.. >.<Let me just see if this program can run.Thanks again for your help!Message was edited by: kageNOhikari
kageNOhikaria at 2007-7-9 21:06:15 > top of Java-index,Java Essentials,New To Java...