title: Trying to perform an action when a button is pressed
body: <p>I am trying to make a game and I made a Button class using the JButton library.</p>
  <p>This code is in the button class:</p>
  <p><code>@Override public void mouseClicked(MouseEvent e) { pressed = true; }</code></p>
  <pre><code>public boolean getPressed(){
      return pressed;
  }
  </code></pre>
  <p>Then in the main java file:</p>
  <pre><code>    Button playButton = new Button(&quot;PLAY&quot;, frame);
      frame.add(playButton);
      
      
      while (true){
          
          
          if (playButton.getPressed())
              System.out.println(&quot;test&quot;);
          
      }
  </code></pre>
  <p>It never seems to print test even though I checked and the boolean value is being changed</p>