Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Whats wrong here?

  1. #1
    Banned
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Whats wrong here?

    i want to make a game and i am stuck. It is not working so i need help fixing it. Will thanks anyone who can help

    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()]);
    		}
    	}			
    }


    Can anyone tell me whats wrong?
    Last edited by copeg; June 8th, 2011 at 08:30 PM.


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Whats wrong here?

    Quote Originally Posted by Java Sucks View Post
    Can anyone tell me whats wrong?
    Not without a more detailed explaination from you. Waht is wrong? When you compile do you get errors? Then coopy and paste the EXACT message here and indicate which line it occurs on. Does the code run but crash? Once again post the error message. Does the code run but exhibit unexpected behaviour/results? Then tell us what it does do and what you expect it to do instead.

    Also wrap tags around your code to make it readible. Add [ highlight=java ] before and [ /highlight ] (without the spaces) after your code. There is a link at the bottom of the page to the BBcode for more information.

  3. #3
    Banned
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Whats wrong here?

    i have no idea what your saying. Can you noob it down please?

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Whats wrong here?

    I'll pass. No interest in playing with a Troll!

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Whats wrong here?

    First, please use the code tags. Next, Junky is correct in mentioning we need more information. "Its not working" is abstract as it gets, and often times will result in responses like "then fix it" - we can't help you if you don't help us understand the problem. If you want detailed help, you must explain the problem you are having in detail, including providing an SSCCE that demonstrates the issue, and answer the questions that Junky asked - Junky's response was 'noobeed down'. Further, I recommend reading the following: How To Ask Questions The Smart Way. Lastly, I sent you a PM, I recommend reading it and taking the suggestions therein
    Last edited by copeg; June 8th, 2011 at 08:51 PM.

Similar Threads

  1. whats wrong?
    By whattheeff in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 25th, 2011, 02:35 PM
  2. could you tell me whats wrong....
    By gonfreecks in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 6th, 2010, 04:35 PM
  3. whats wrong with this one....
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 6th, 2009, 10:08 AM
  4. help whats wrong
    By silverspoon34 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 3rd, 2009, 01:41 AM
  5. [SOLVED] whats wrong with my IDE
    By chronoz13 in forum Java IDEs
    Replies: 2
    Last Post: August 27th, 2009, 06:34 AM