zheka 0 Newbie Poster

Hi all,
I am very new to the Java and would like to get help with the Swing components in the thread: below is an ActionListener for the MOVE button which would simulate random movement of random circles on JPanel. I have created separate class RandomCircles which extends JPanel and generates stationary random circles, then another class RandomCirclesAnimation which also extends JPanel and creates an array of few JPanels with random circles. Now I would like dynamically show these JPanels, replacing each other until the button STOP is pressed. What happens is that "for" loop goes only once through the array doing these replacements and then just continue with the "while" loop ignoring the existence of this array, and no replacements are happening. Here is my code:

class MoveHandler implements ActionListener, Runnable {

    RandomCirclesAnimation rca;
    private volatile int numberOfCircles;
    private volatile Thread worker;
    private volatile RandomCircles[] random_circles;
    private volatile boolean flagMove = true;

    MoveHandler() {
    }

    public void actionPerformed(ActionEvent e) {
        numberOfCircles = info.numberOfCircles();
        rca = new RandomCirclesAnimation(numberOfCircles);
       Thread worker = null;
        random_circles = rca.animationArray();

        if (worker != null && worker.isAlive()) {
            worker.interrupt();
        } else {
            worker = new Thread(this);
            worker.start();

        }

    } // end of "actionPerformed"

    public void run() {

        while (flagMove != false) {

            for (int i = 0; i < 5; i++) {
               f.getContentPane().remove(circlePanel);
                circlePanel = random_circles[i];
                f.getContentPane().add(circlePanel, 0);
                f.validate();
                try {
                    Thread.sleep(500);

                } catch (Exception ex) {

                    Thread.currentThread().interrupt();
                    System.out.println("Interruption!");
                    break;
                }
            } // end of "for" loop
            if (random_circles == null) {
                System.out.println("No array!");
            }
             flagMove = bp.flagMove();

        } // end of "while " loop
    } // end of run()
} // end of the class "MoveHandler"