Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

My Rock Paper Scissors Game

807599Feb 21 2007 — edited Feb 21 2007
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.*;

public class RandomJava extends 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);
	}
	
	public static void main(String args[])
	{
		RandomJava application = new RandomJava();
		
		application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	private class ButtonHandler implements ActionListener{
		
		public void 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; }
			else if(paper.isSelected()) {coms = Math.round((ComChoice.length - 1) * Math.random()); put += "Your choice: PAPER\t" + "Computer's Choice: " + coms; yours = 1; }
			else if(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!"; }
			else if(yours > coms) {put += "\nYOU WON!"; }
			else if(coms > yours) {put += "\nYOU LOST!"; }
			
			result.setText(put);
		}
	}
}
Message was edited by:
kageNOhikari
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 21 2007
Added on Feb 21 2007
2 comments
597 views