title: Why doesn't my button change after clicking?
body: <p>Please help with the problem. I need the label to change to <code>X</code> after click on my button, and to <code>O</code> after the second click. Please check my code below, and tell me what is wrong? My program just changes the label to <code>X</code>, but doesn't change to <code>O</code> :(</p>
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  public class test extends MouseAdapter {
      JPanel windowContent;
      JFrame frame;
      Button myButton;
      test() {
          windowContent = new JPanel();
          FlowLayout fl = new FlowLayout();
          windowContent.setLayout(fl);
          
          myButton = new Button(&quot;Change text&quot;);
          myButton.addMouseListener(this);
          windowContent.add(myButton);
          
          frame = new JFrame(&quot;Tic Tac Toe&quot;);
          frame.setContentPane(windowContent);
          frame.setSize(100, 100);
          frame.setVisible(true);
      }
      
      public void mouseClicked(MouseEvent e) {
          int i = 0;
          if (i == 0) {
              myButton.setLabel(&quot;X&quot;);
              i++;
          } else if (i == 1) {
              myButton.setLabel(&quot;O&quot;);
          }
      }
      
      public static void main(String[] args) {
          new test();
      }
  
  }
  </code></pre>