title: How to use a getY() method in java?
body: <p>I have found loads of questions on this website on how to use getter functions in java but I haven't found many real answers to most of these questions which is why I am asking this.</p>
  
  <p>Here is a piece of my code:</p>
  
  <p>y - Height of shape</p>
  
  <p>x - Width of shape</p>
  
  <p>posX - Position of shape on x axis</p>
  
  <p>posY - Position of shape on y axis</p>
  
  <p>speed - Speed travelling</p>
  
  <p>speedY - Equal to speed, specially made for movement on y axis</p>
  
  <p>halfY - Half of y and distance shape should move down before turning around</p>
  
  <pre><code>public void actionPerformed(ActionEvent e){
      if(posY == 0){
          posX = posX + speed;
      }
      if((posX &lt;= 0)&amp;&amp;(posY != 0)){
          posX = posX + speed - speed;
          posY = posY + speedY;
      }
      if(posX &gt;= 600 - x){
          posX = posX + speed - speed;
          posY = posY + speedY;       
      }
      if(posY &gt;= y - halfY){
          posX = posX - speed;
      }
      repaint();
  }
  </code></pre>
  
  <p>After moving I want to get the current y position of the shape and use it in another method, but I am unsure how to do this and this is also a void function so I am unsure how to get the y and use it in another method IN THE SAME CLASS.</p>