Results 1 to 2 of 2
- 12-07-2008, 09:07 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 16
- Rep Power
- 0
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); }
-
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
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.Java Code:play.setEnabled(false);
Good luck and HTH.
Similar Threads
-
Implementing "Game Over" in Minesweeper game based on Gridworld framework.
By JFlash in forum New To JavaReplies: 2Last Post: 08-05-2010, 04:49 AM -
Fill a menu dynamically when menu is shown
By Java Tip in forum SWTReplies: 0Last Post: 07-07-2008, 04:47 PM -
How to use SWT menu and menu event
By Java Tip in forum SWTReplies: 0Last Post: 07-07-2008, 04:46 PM -
React to menu action and checkbox menu
By Java Tip in forum javax.swingReplies: 0Last Post: 06-27-2008, 07:50 PM -
how to create Popup Menu with Sub Menu while right-clicking the JTree Node??
By Kabiraa in forum AWT / SwingReplies: 7Last Post: 05-09-2008, 07:54 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks