can anyone teach me how to use a timer in java,
for example: i want my oval to appear after 5 seconds. and how to put random coordinates/width/height, for example:
g.drawOval()
<-- numbers inside should be random
.
can anyone teach me how to use a timer in java,
for example: i want my oval to appear after 5 seconds. and how to put random coordinates/width/height, for example:
g.drawOval()
<-- numbers inside should be random
.
you just need to create variables containing double values generated with a randomizer.
double coordx=Math.random(); //this creates a random double value between 0 and 0.9999
double coordy=Math.random()*5;//between 0 and 4.9999
double width=(Math.random()+1)*5;//between 1 and 5.999
then you write a method like
public void drawIt(double coordx, double coordy, double width){
Thread.sleep(1000); //time in miliseconds to wait before continuing
g.drawOval(coordx,coordy,width); //i assume you already have drawOval and g
}
hope this helped you.
even easier version:
public void drawIt(){
double coordx=Math.random(); //this creates a random double value between 0 and 0.9999
double coordy=Math.random()*5;//between 0 and 4.9999
double width=(Math.random()+1)*5;//between 1 and 5.999
Thread.sleep(1000); //time in miliseconds to wait before continuing
g.drawOval(coordx,coordy,width); //i assume you already have drawOval and g
}