title: Java Click on a object and output a message
body: <p>Im currently making a game in my spare time to improve my java but im having trouble with one of the things i want to do. Ive made the game so i can put a item into a certain position. In this example its a tower in a certain location. When this tower is placed in this location and i click on the tower i want it to output a message. However ive tried many ways to do this and i havent been able to find a solution. The code i have for this is:</p>
  
  <pre><code>public static void click(int X, int Y){
      System.out.println("X. " + X + " Y. " + Y);
  
      if(Screen.room.block[X][Y].airID == Value.tower){
          System.out.println("Tower clicked");
      }
  }   
  </code></pre>
  
  <p>When the tower is placed in a location the code i use for this is:</p>
  
  <pre><code>        if(holdsItem){
                  for(int y=0; y&lt;Screen.room.block.length; y++){
                      for(int x=0; x&lt;Screen.room.block[0].length; x++){
                          if(Screen.room.block[y][x].contains(Screen.mse)){
                              if(Screen.room.block[y][x].groundID != Value.ground &amp;&amp; Screen.room.block[y][x].airID == Value.tower){
                                  Screen.room.block[y][x].airID = heldID;
  
  
                          }
                      }
                  }
              }
          }
  </code></pre>
  
  <p>When i put down a tower by:</p>
  
  <pre><code>System.out.println(Screen.room.block[y][x]);
  </code></pre>
  
  <p>i get</p>
  
  <pre><code>Block[x=243,y=260,width=52,height=52]
  </code></pre>
  
  <p>This works fine and the tower is placed. I then wanted to use the location of what the tower is placed and then if that location is pressed the message would print in the console. However this doesnt happen. Can anyone help me fix this problem.</p>
  
  <p>I use a mouse listener which is:</p>
  
  <pre><code>    public void mouseClicked(MouseEvent e) {
          e.getX();
          e.getY();
          Block.click(e.getX(), e.getY());
  
      }
  </code></pre>
  
  <p>When i click on a location i get:</p>
  
  <pre><code>System.out.println("X. " + X + " Y. " + Y);
  
  X. 257 Y. 298
  </code></pre>
  
  <p>if this helps.</p>