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.
Here is a piece of my code:
y - Height of shape
x - Width of shape
posX - Position of shape on x axis
posY - Position of shape on y axis
speed - Speed travelling
speedY - Equal to speed, specially made for movement on y axis
halfY - Half of y and distance shape should move down before turning around
public void actionPerformed(ActionEvent e){
if(posY == 0){
posX = posX + speed;
}
if((posX <= 0)&&(posY != 0)){
posX = posX + speed - speed;
posY = posY + speedY;
}
if(posX >= 600 - x){
posX = posX + speed - speed;
posY = posY + speedY;
}
if(posY >= y - halfY){
posX = posX - speed;
}
repaint();
}
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.