Note that there are some explanatory texts on larger screens.

plurals
  1. POWait for button press JButton
    primarykey
    data
    text
    <p>I am looking for a way of making my program wait until a button is pressed to continue the function. In my main function i am calling a function which shows my basic GUI using JPanel, buttons and labels. ofcourse, it shows the GUI and ends that function not allowing me to alter the GUI. </p> <pre><code> public static Player player = new Player(); public static Gui gui = new Gui(); public static boolean inMain = true; public static boolean inBattle = false; public static void main(String[] args){ showMainGui(); } </code></pre> <p>I think what im looking for is something that will look like this:</p> <pre><code>public static void main(String[] args){ showMainGui(); while(inBattle == false){ // wait until inBattle changes } } </code></pre> <p>That while loop will loop and wait until a button created in showMainGui changes inBattle to true. How could i do this exactly? This is rather confusing me. My goal is to click a JButton and the buttons change to different buttons</p> <p>My action listener for my button created on the showMainGui();</p> <pre><code>public class Hunt implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { MainClass.inBattle = true; } } </code></pre> <p>and here is my showMainGui() method</p> <pre><code>public static void showMainGui(){ gui.panel.add(gui.healthLabel); gui.panel.add(gui.pbsLabel); gui.panel.add(gui.staminaLabel); gui.panel.add(gui.levelLabel); //Adding initial buttons gui.panel.add(gui.exploreButton); gui.panel.add(gui.huntButton); gui.panel.add(gui.newsLabel); gui.panel.add(gui.effectLabel); updateGui(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload