I'm writing a small JAVA applet.
Which gets a random number between 1 to 6 and prints them on APPLET screen. What i want to do is.. Loop 50 times on screen and print various randdom numbers. [Each time clearing the previous number].
And after that loop.. It prints any 1 final random number on applet..
My problem is: The loop. It is printing all numbers over each ither and screen is not getting cleared. What is wrong? I have tried many methods of clearing applet screen like drawing rectangle or using clearRect() function. Nothing is working. Here's the code.
import java.applet.Applet;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.util.Random;
public class Shapes extends Applet{
/**
*
*/
private static final long serialVersionUID = 1L;
Random r = new Random();
Dimension d = getSize();
Font f = new Font("TimesRoman", Font.BOLD, 96);
public void paint(Graphics g)
{
for(int m=0;m<=50;m++){
int k = Math.abs((r.nextInt()) % 6) + 1;
g.setFont(f);
g.setColor(Color.BLACK);
g.drawString(String.valueOf(k) , 70, 100);
g.setColor(Color.WHITE);
g.drawRect(0, 0, d.width, d.height);
try{Thread.sleep(70);}catch(Exception e){}
}
}
}