Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would +1 <a href="https://stackoverflow.com/a/17989811/2634190">Peters answer</a>, but I feel this needs some elaboration.</p> <p>There's absolutely <strong>no need for a while loop or additional threading</strong>. Simply add listeners to your UI components. Here's a very simple example:</p> <pre><code> JButton button = new JButton("This is a button!"); //Add action listener to button button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //Perform function when button is pressed System.out.println("You clicked the button"); } }); </code></pre> <hr> <p>You have added the action listener while still keeping the while loop, why? REMOVE the while loop and use the listener.</p> <p>Repeating <a href="https://stackoverflow.com/a/17989811/2634190">Peter</a> again, but <a href="http://docs.oracle.com/javase/tutorial/uiswing/events/index.html" rel="nofollow noreferrer">RTFM</a>. Just <a href="http://docs.oracle.com/javase/tutorial/uiswing/events/index.html" rel="nofollow noreferrer">read the documentation</a>, which provides clear examples. There's no good reason to use that loop.</p> <hr> <p>Your application is not crashing, it's doing exactly what you're telling it to do:</p> <pre><code>public static void main(String[] args){ showMainGui(); while(inBattle == false){ // wait until inBattle changes } } </code></pre> <p>You're saying, WHILE inBattle is false, do nothing, but if inBattle is true, do nothing then end the main function -- What do you expect it to do after you click the button if there's nothing to be done?</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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