title: How to access a JButton from another class
body: <p>I have two classes 'UserInterface' and a 'GameEngine' I have declared a JButton component in the UserInterface and I am trying to use one of the variables i.e use the variable 'button1' from 'UserInterface' in the 'horizontalWin' method from the class 'GameEngine'.</p>
  
  <p>I got this error instead "cannot find symbol - variable button1"</p>
  
  <p>Userinterface:</p>
  
  <pre><code>public class UserInterface implements ActionListener
  {
   private GameEngine game;
   private JFrame frame;
  
   JButton button1 = new JButton("");
   JButton button2 = new JButton("");
   JButton button3 = new JButton("");
   JButton button4 = new JButton("");
   JButton button5 = new JButton("");
   JButton button6 = new JButton("");
   JButton button7 = new JButton("");
   JButton button8 = new JButton("");
   JButton button9 = new JButton("");
  
   /**
   * Create a user interface.
   * @param engine The game's engine.
   */
   public UserInterface(GameEngine engine)
   {
      game = engine;
      makeFrame();
   }
  
   //some methods
  }
  </code></pre>
  
  <p>GameEngine:</p>
  
  <pre><code>public class GameEngine {
   private String buttonName;
   boolean winner = false;
   byte count;
  
  public GameEngine()
  {
      count = 0;
  }
  
  public void horizontalWin()
  {
      if(button1.getText()==button2.getText() &amp;&amp; button2.getText()==button3.getText() &amp;&amp; button1.getText()!="" )
      {
          winner=true;
          playAgain(buttonName);
  
      }
      // Horizontal win row 2
      else if(button4.getText()==button5.getText() &amp;&amp; button5.getText()==button6.getText() &amp;&amp; button4.getText()!="" )
      {
          winner=true;
          playAgain(buttonName);
  
      }
      // horizontal win row 3
      else if(button7.getText()==button8.getText() &amp;&amp; button8.getText()==button9.getText() &amp;&amp; button7.getText()!="")
      {
          winner=true;
          playAgain(buttonName);
  
      }
  
  }
  </code></pre>