I have this timer used to move Star.png through JFrame & JPanel
function to move the star which has the timer :
private final static int HEIGHT = 300;
.
.//more code here
.
.
  x=y=0;
.
. 
public void downRight() {
    Timer localTimer = new Timer(100, null);
      localTimer.setRepeats(false);
    localTimer.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {    
                x++;
                y++;
                repaint();
        }
    });
    int xTest=0;
    while (y < HEIGHT) {
        System.out.println("x "+(++xTest)+" y "+y);
        localTimer.start();
   }
    System.out.println("Reached");
}
When Running the timer and testing xTest,y values found the following:
x 1 y 0
x 2 y 0
x 3 y 0
..... More Outputs here
.....
x 1653 y 1
x 1654 y 1
......
......
x 285836 y 299
x 285837 y 299
Reached
So What is happening here? Why xTest is too greater than y although the both are in the same scope ?