6 Replies - 4596 Views - Last Post: 11 March 2009 - 11:32 AM Rate Topic: -----

#1 alyaika  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-March 09

Rock-Paper-Scissors Applet

Post icon  Posted 11 March 2009 - 09:14 AM

:blink: please help me to make the simple code using java applet to created rock paper scissors game
Is This A Good Question/Topic? 0
  • +

Replies To: Rock-Paper-Scissors Applet

#2 Nykc  Icon User is offline

  • Gentleman of Leisure
  • member icon

Reputation: 731
  • View blog
  • Posts: 8,644
  • Joined: 14-September 07

Re: Rock-Paper-Scissors Applet

Posted 11 March 2009 - 09:15 AM

Please show us some work and we would be glad to help you.

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#3 alyaika  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-March 09

Re: Rock-Paper-Scissors Applet

Posted 11 March 2009 - 09:20 AM

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
public class prs extends JPanel implements ActionListener, ItemListener
{
	private final Point FRAME_ORIGIN = new Point(450,250);
	private final Color clrBackground = new Color(255,255,255);
	private final Color clrForeground = new Color(0,0,0);
 
	private JComboBox cboxWeapon;
	private JTextField txtCPUWeapon, txtWins, txtLoses, txtDraws;
	private JLabel lblPlayerWeapon, lblCPUWeapon, lblWins, lblLoses, lblDraws, lblStatus, lblPlayerWeaponIcon, lblCPUWeaponIcon;
	private JButton cmdPlay, cmdReset;
	private ImageIcon[] imgWeapon;
	private JPanel panRoot, panPlayerArea, panPlayerWeapon, panCPUArea, panCPUWeapon, panStatusArea, panGo, panCounters, panWins, panLoses, panDraws;
 
	private prsEngine engine = new prsEngine();
	private objCreateAppletImage createImage = new objCreateAppletImage();
 
	private boolean errorWithImages = false;
 
	public static void main(String[] args)
	{
 
	     JFrame frame = new JFrame("Paper Rock Scissors Game"); 
		  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);         
        JComponent paneMain = new prs();
        paneMain.setOpaque(true);
	     paneMain.setPreferredSize(new Dimension(420,350));
        frame.setContentPane(paneMain);   
        frame.pack();
        frame.setVisible(true);
 
    }
 
	public prs ()
	{
 
		cboxWeapon = new JComboBox(engine.getWeapon());
		cboxWeapon.addItemListener(this);
 
		txtCPUWeapon = new JTextField(engine.getStrCPUWeapon(), 5);		
		txtWins = new JTextField("0", 5);
		txtLoses = new JTextField("0", 5);
		txtDraws = new JTextField("0", 5);
 
		txtCPUWeapon.setEditable(false);
		txtWins.setEditable(false);
		txtLoses.setEditable(false);
		txtDraws.setEditable(false);
 
		lblPlayerWeapon = new JLabel("Choose Your Weapon:", JLabel.CENTER);
		lblCPUWeapon = new JLabel("PC's Weapon:", JLabel.CENTER);
		lblWins = new JLabel("Amount of Wins:", JLabel.RIGHT);
		lblLoses = new JLabel("Amount of Loses:", JLabel.RIGHT);
		lblDraws = new JLabel("Amount of Draws:", JLabel.RIGHT);
		lblStatus = new JLabel("", JLabel.CENTER);
 
		lblPlayerWeaponIcon = new JLabel("", JLabel.CENTER);
		lblCPUWeaponIcon = new JLabel("", JLabel.CENTER);
 
		lblPlayerWeaponIcon.setPreferredSize(new Dimension(150,150));
		lblCPUWeaponIcon.setPreferredSize(new Dimension(150,150));
 
		cmdPlay = new JButton("Go!");
		cmdReset = new JButton("Restart");
 
		cmdPlay.addActionListener(this);
		cmdReset.addActionListener(this);
 
		try
		{
 
			imgWeapon = new ImageIcon[3];
 
			for (int i = 0; i < 3; i++)
			{
				imgWeapon[i] = createImage.getImageIcon(this, "/" + engine.getWeapon(i) + ".jpg", "Icon for " + engine.getWeapon(i), 13000); // images place at the same directory!
			}
 
			lblPlayerWeaponIcon.setIcon(imgWeapon[0]);
			lblCPUWeaponIcon.setIcon(imgWeapon[0]);
 
		}
		catch (Exception ex) //The game works without the images, so carry on
		{
			errorWithImages = true;
		}
 
		setLayout(new BorderLayout());
		panRoot = new JPanel(new BorderLayout());
		panPlayerArea = new JPanel(new BorderLayout());
		panPlayerWeapon = new JPanel(new BorderLayout());
		panCPUArea = new JPanel(new BorderLayout());
		panCPUWeapon = new JPanel(new BorderLayout());
		panStatusArea = new JPanel(new BorderLayout());
		panGo = new JPanel();
		panCounters = new JPanel(new GridLayout(3,1,2,2));
		panWins = new JPanel();
		panLoses = new JPanel();
		panDraws = new JPanel();
 
		add(panRoot, BorderLayout.CENTER);
			panRoot.add(panPlayerArea, BorderLayout.WEST);
				panPlayerArea.add(panPlayerWeapon, BorderLayout.NORTH);
					panPlayerWeapon.add(lblPlayerWeapon, BorderLayout.NORTH);
					panPlayerWeapon.add(cboxWeapon, BorderLayout.SOUTH);
				panPlayerArea.add(lblPlayerWeaponIcon, BorderLayout.SOUTH);
			panRoot.add(panCPUArea, BorderLayout.EAST);
				panCPUArea.add(panCPUWeapon, BorderLayout.NORTH);
					panCPUWeapon.add(lblCPUWeapon, BorderLayout.NORTH);
					panCPUWeapon.add(txtCPUWeapon, BorderLayout.SOUTH);
				panCPUArea.add(lblCPUWeaponIcon, BorderLayout.SOUTH);
			panRoot.add(panStatusArea, BorderLayout.SOUTH);
				panStatusArea.add(panGo, BorderLayout.NORTH);
					panGo.add(cmdPlay);
					panGo.add(cmdReset);
					panGo.add(lblStatus);					
				panStatusArea.add(panCounters, BorderLayout.SOUTH);
					panCounters.add(panWins);
						panWins.add(lblWins);
						panWins.add(txtWins);
					panCounters.add(panLoses);
						panLoses.add(lblLoses);
						panLoses.add(txtLoses);
					panCounters.add(panDraws);
						panDraws.add(lblDraws);
						panDraws.add(txtDraws);
 
		panRoot.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
 
		setBackground(clrBackground);
		panRoot.setBackground(clrBackground);
		panPlayerArea.setBackground(clrBackground);
		panPlayerWeapon.setBackground(clrBackground);
		panCPUArea.setBackground(clrBackground);
		panCPUWeapon.setBackground(clrBackground);
		panStatusArea.setBackground(clrBackground);
		panGo.setBackground(clrBackground);
		panCounters.setBackground(clrBackground);
		panWins.setBackground(clrBackground);
		panLoses.setBackground(clrBackground);
		panDraws.setBackground(clrBackground);
 
		lblPlayerWeapon.setForeground(clrForeground);
		lblCPUWeapon.setForeground(clrForeground);
		lblWins.setForeground(clrForeground);
		lblLoses.setForeground(clrForeground);
		lblDraws.setForeground(clrForeground);
		txtWins.setForeground(clrForeground);
		txtLoses.setForeground(clrForeground);
		txtDraws.setForeground(clrForeground);
		txtCPUWeapon.setForeground(clrForeground);
 
	}
 
	public void reset ()
	{
 
		cboxWeapon.setSelectedIndex(0);
		lblStatus.setText("");
 
		engine.reset();
 
	}
 
	public void actionPerformed (ActionEvent e)
	{
 
		if (e.getSource() == cmdReset)
		{
			reset();
		}
		else
		{						
			lblStatus.setText(engine.play(cboxWeapon.getSelectedIndex()));						
		}
 
		txtCPUWeapon.setText(engine.getStrCPUWeapon());
		txtWins.setText(Integer.toString(engine.getWins()));
		txtLoses.setText(Integer.toString(engine.getLoses()));
		txtDraws.setText(Integer.toString(engine.getDraws()));
 
		if (!errorWithImages)
		{			
			lblCPUWeaponIcon.setIcon(imgWeapon[engine.getCPUWeapon()]);			
		}
 
	}
 
	public void itemStateChanged (ItemEvent e)
	{
 
		if (!errorWithImages)
		{
			lblPlayerWeaponIcon.setIcon(imgWeapon[cboxWeapon.getSelectedIndex()]);
		}
	}			
}


*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 11 March 2009 - 11:34 AM

Was This Post Helpful? 0
  • +
  • -

#4 Nat3TheGreat13  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 162
  • Joined: 09-February 09

Re: Rock-Paper-Scissors Applet

Posted 11 March 2009 - 11:06 AM

Please post your code between
Paste Your Code Here

Please identify what you have a question about.
What kind of errors are you having?

This post has been edited by Nat3TheGreat13: 11 March 2009 - 11:06 AM

Was This Post Helpful? 0
  • +
  • -

#5 crazyjugglerdrummer  Icon User is offline

  • GAME OVER. NERD WINS.
  • member icon

Reputation: 119
  • View blog
  • Posts: 690
  • Joined: 07-January 09

Re: Rock-Paper-Scissors Applet

Posted 11 March 2009 - 11:12 AM

alyaika, you could have at least let him give it a try xD. We want to make sure people understand what they're learning, so we can't just do their stuff for them.

Nat3, notice that when you actually type the code tags, they turn into the box thingy ;) type [ code] post code here [ /code] without the spaces to get the code box thingy :D

Hope this helps!
Was This Post Helpful? 0
  • +
  • -

#6 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Rock-Paper-Scissors Applet

Posted 11 March 2009 - 11:19 AM

Or you could just use the image shortcut.

:code:

Just like a smiley, the rolleyes one for example. It's just code between 2 colons.

This post has been edited by Locke: 11 March 2009 - 11:22 AM

Was This Post Helpful? 0
  • +
  • -

#7 Nykc  Icon User is offline

  • Gentleman of Leisure
  • member icon

Reputation: 731
  • View blog
  • Posts: 8,644
  • Joined: 14-September 07

Re: Rock-Paper-Scissors Applet

Posted 11 March 2009 - 11:32 AM

@crazyjugglerdrummer- that is the OP code however I doubt it is his, there is no description of what issues he is having.

I mean seriously if you want our help tell us what is wrong, what you are trying to do, and what needs to be done.

This post has been edited by Nykc: 11 March 2009 - 11:33 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1