title: Passing data from GUI to another class in Java
body: <p>I am doing a project that consist on creating a Battleship Game.
  I have the following classes:</p>
  
  <ul>
  <li><code>Battleship</code> (main class)</li>
  <li><code>Player</code>,</li>
  <li><code>Game</code>,</li>
  <li><code>Board</code>,</li>
  <li><code>Visualisation</code> (GUI class where I have a <code>gridLayout</code> of <code>JButtons</code>) where the user press the <code>JButton</code> where want to insert the ship.</li>
  </ul>
  
  <p>First of all a create a new <code>Game</code> with some parameters such as the size of the board. Then inside the class <code>Game</code> I do a new <code>Visualisation</code>. Inside this class I have done the <code>actionListener</code> and the <code>actionPerformed</code>.</p>
  
  <p>My question is how I can pass the information, for example, of which <code>JButton</code> I have pressed (to insert the ship in that cell of the <code>gridLayout</code>) to the class <code>Game</code>? This is what I have:</p>
  
  <pre><code>Class Game
   private Player _user;
   private Player _computer;
  </code></pre>
  
  <p>And then I want to check the board of the <code>_user</code> if that positions are available to insert the ship. <code>_user.MethodOfClassPlayer();</code></p>
  
  <pre><code>Class Player
    private int id;
    private String name;
    private Board _boardPlayer
  </code></pre>
  
  
  
  <pre><code>Class Board
    private int size;
    private int[][] _board = null ;
  </code></pre>
  
  <p>Function actionPerformed</p>
  
  <pre><code>  public void actionPerformed(ActionEvent e) {
      for ( int i = 0; i &lt; tUsuariCPU.length; i++ ){
              for ( int j = 0; j &lt; tUsuariCPU[i].length; j++ ){
                  if ( e.getSource() == tUsuariCPU[i][j] ){
                          buttonPressedUser(i,j);
                          JButton temp = (JButton) e.getSource() ;
                          temp.setBackground(java.awt.Color.ORANGE);
      }
  </code></pre>
  
  <p>I want to pass the information of the JButton pressed to Game class to know if for that Player that position is available or not for putting the ship. If it is available so I will paint the JButton
  I hope you understand me.  </p>