I'm working on a project that draws a circle every 1000 millisec but when my loop finishes it calls the repaint manager and all my circles are removed and redrawn. Any ideas on how to prevent the repaint?
import java.awt.*; import javax.swing.*; import java.util.*; import java.awt.image.*; public class Forest extends JApplet { Random rand; JButton one; public void init() { setLayout(new FlowLayout()); one = new JButton("one"); add(one); } public void paint(Graphics g) { super.paint(g); int treeX = getWidth()-50, treeY=getHeight()-50, count=0; Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Color colorTree = new Color(randomGenerator(255),randomGenerator(255),randomGenerator(255)); //loop for painting trees while(count < 3){ wait(1000); paintTree(g2d,randomGenerator(treeX),randomGenerator(treeY),colorTree); colorTree = new Color(randomGenerator(255),randomGenerator(255),randomGenerator(255)); count = count + 1; } } //Method that builds tree based on random x y coordinates public void paintTree(Graphics2D gt, int x, int y, Color treeColor){ gt.setColor(treeColor); gt.fillOval(x,y,50,50); gt.setColor(new Color(128,64,0)); gt.fillRect((x+15),(y+47),20,40); } //method to return random number with upper bound passed public int randomGenerator(int randNum){ rand = new Random(); return rand.nextInt(randNum); } //wait before drawing next tree public void wait (int n){ long t0,t1; t0=System.currentTimeMillis(); do{ t1=System.currentTimeMillis(); } while (t1-t0<n); } }