Issue when switching between menus
Author |
Message |
xHoly-Divinity
|
Posted: Wed Apr 25, 2007 8:45 pm Post subject: Issue when switching between menus |
|
|
Ok here is the problem: My main program executes my main menu. My main menu returns a value to the main prog indicating when the 'play' button was hit. It works fine until..... Until I enter a new menu. So from my main menu, when I click on say 'options', my main menu is hidden, and then my options menu is executed. When the back button is hit, the options menu gets hidden and it creates a NEW main menu. So now when I click 'play', because it is in essence a new program that was executed, my main program will not receive any input from it. I also tried closing instead of hiding, but it doesn't work.
What I need to do is 'reveal' my main menu. I've tried doing this in my main program, and also my menu class. When I do it in the menu class, I have to enter a 'while' loop (which keeps checking when the 'back' button was hit from the other class), but if I do, the other menu will not load.
code: |
//MAIN MENU CLASS
public boolean checkStartGame () //Returns value to main class
{
return startGame;
}
public void actionPerformed (ActionEvent event)
{
if (event.getSource () == data) //If data button is clicked, executes the 'data' menu
{
DataScreen o = new DataScreen (); //Runs the data menu
setVisible (false);
while (o.mainMenuSetVisible == false) //Exits when the back button from data menu is hit
o.checkMenuVisibility ();
setVisible (true);
}
}
|
code: |
public boolean checkMenuVisibility () //The value returned to the Main Menu to see if 'back' was hit
{
return mainMenuSetVisible;
}
public void actionPerformed (ActionEvent event)
{
if (event.getSource () == back) //If back is clicked, it returns to the main menu
{
mainMenuSetVisible = true;
setVisible (false);
//SudokuMenu s = new SudokuMenu (); --> Creates new menu which I do not want
}
}
}
|
Help or ideas are much appreciated. Thanks!! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
HellblazerX
|
Posted: Thu Apr 26, 2007 12:59 pm Post subject: RE:Issue when switching between menus |
|
|
Why do you have to create a new main menu every time you pressed back? I did something like this for my FP last year, and the way I did it is I had a reference in all my menus to my main program (I'm assuming all your menus are JPanels, and your main program is a JFrame which contains all of it), and whenever I'd click the back button, I have my main program remove my current menu, and readd my main menu. It looked like this:
code: | //Switches to the main menu.
public void switchToMenu () {
content.removeAll ();
content.add (menuPanel);
pack ();
repaint ();
menuPanel.setFocusable (true);
} |
Content refers to my main program class, and menuPanel is my main menu. |
|
|
|
|
|
xHoly-Divinity
|
Posted: Thu Apr 26, 2007 5:42 pm Post subject: Re: Issue when switching between menus |
|
|
Actually.... all my menus are JFrames and are pretty much independent of each other...
I will give your way a shot and see how it goes. I'll follow up if I have any other problems. Thanks |
|
|
|
|
|
|
|