java controlling multithread run () method
<pre><code>package test;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPanel;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseMotionAdapter;
import java.awt.geom.*;


public class Board extends JPanel implements Runnable, MouseListener {

    private Star star;
    private Thread animator;
    ArrayList&lt;Star&gt; items=new ArrayList&lt;Star&gt;();
    private int mouseX = 0;
    private int mouseY = 0;
    private boolean draw = false;


    public Board() {
        setBackground(Color.WHITE);
        setDoubleBuffered(true);
        addMouseListener(this);
        //addStar();
    }

    public void addStar() {
        star=new Star(25,0,0);
        Star star2=new Star(50,20,25);
        items.add(star2);
        items.add(star); 
        repaint();
        run();
        System.out.println("abc");
    }

    public void addNotify() {
        super.addNotify();

        animator = new Thread(this);
        animator.start();

    }

    public void paint(Graphics g) {
        if (draw == true) {


            super.paint(g);
            Graphics2D g2d = (Graphics2D)g;

                for (Star s : this.items) {
                    g2d.drawImage(s.starImage, s.x, s.y, this);
                }

            Toolkit.getDefaultToolkit().sync();
            g.dispose();

        }
    }

    public void run() {

        if (!items.isEmpty()) {
            while(true){
                try {
                    for (Star s : this.items) {
                        s.move();
                    }
                    repaint();

                    Thread.sleep(star.delay);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Board.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }

    public void mouseClicked(MouseEvent e) {
        //drawCircle(e.getX(), e.getY());
        addStar();

        draw=true;
        //repaint();


    }

    public void mouseExited(MouseEvent e) {

    }

    public void mousePressed(MouseEvent e) {

    }

    public void mouseReleased(MouseEvent e) {

    }

    public void mouseEntered(MouseEvent e) {

    }    


}
</code></pre>

<p>i want to run the thread when i clicked the jPanel, when the mouse clicked, addStar method will be ran. My problem is, the run() method, when the classes start, is the run method must run automatically? Can i control it to run after i clicked the jPanel?</p>

<p>This program can work if add addStar() method to constructor and remove </p>

<pre><code>if (!items.isEmpty()) {
}
</code></pre>
