Results 1 to 2 of 2
  1. #1
    pjr5043 is offline Member
    Join Date
    Sep 2008
    Posts
    16
    Rep Power
    0

    Default Need help with a menu button in a game

    hello, i am working on a video game for my class. i have an option menu that lets you select a character, then you hit the play button and it goes into the game. the problem is if i don't select a character i can still hit play, but then there is no character in the game. i am having trouble writing the correct if statements so that i cannot hit play until i have selected a character here is the code, the play button is the (opt.play) and the charcters are (opt.jb1-jb3) they are radio buttons.
    Java Code:
        }
          public void actionPerformed(ActionEvent e)
        {
        	Object obj = e.getSource();
        	
        	if (obj==set.info)
        	{
        		remove(set);
        		add(ins);
        		validate();
        		repaint(); 
        	}
        	if (obj==set.play)
        	{
        		remove(set);
        		add(opt);
        		validate();
        		repaint(); 
        	}
        	if (obj==set.score)
        	{
        		remove(set);
        		add(sco);
        		validate();
        		repaint();
        	}
        	if(obj == opt.play)
    		{
    		    remove(opt);
        		add(gam);
        		validate();
        		repaint(); 
        
        		
    		}
    		if(obj ==ins.back)
    		{
    			remove(ins);
    			add(set);
        		validate();
        		repaint();
    		}
    		if(obj==sco.back)
    		{
    			remove(sco);
    			add(set);
        		validate();
        		repaint();
    		}
    		if(obj==gam.back)
    		{
    			remove(gam);
    			add(set);
        		validate();
        		repaint();
    		}
    		if(obj==opt.back)
    		{
    			remove(opt);
    			add(set);
        		validate();
        		repaint();
    		}
    		
        	if(obj==opt.jb1)
    		{
    		gam.width=50;
      		gam.height=34;
      		gam.b5.setIcon(imagelogo);
      		
    		}
    		if(obj==opt.jb2)
    		{
      		gam.width=50;
      		gam.height=83;
      		gam.b5.setIcon(imagelion);
    
    		}
    		if(obj==opt.jb3)
    		{
      		gam.width=50;
      		gam.height=118;
      		gam.b5.setIcon(imagejoe);
    
    		}

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    How about disabling the play button initially and then enable it only after a character radio button has been selected. You disable the play button with
    Java Code:
    play.setEnabled(false);
    and enable it with setEnabled(true). Also, I recommend that you use more than one ActionListener here as you should have buttons share action listeners only if they share the same or very similar actions.

    Good luck and HTH.

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2010, 05:49 AM
  2. Fill a menu dynamically when menu is shown
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 05:47 PM
  3. How to use SWT menu and menu event
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 05:46 PM
  4. React to menu action and checkbox menu
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 08:50 PM
  5. Replies: 7
    Last Post: 05-09-2008, 08:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •