Program to display numbers from 1 to 10 on Applet such that each number will be display after delay of 100 ms
This makes the use of Thread's sleep( ) method which causes currently executing thread to sleep for given number of milliseconds. In output it will print the numbers from 1 to 10 with a delay of 100ms.
PROGRAM
OUTPUT
C:\>javac Print1To10Num.java
C:\>appletviewer Print1To10Num.java
PROGRAM
import java.awt.*; // import awt package
import java.applet.*; // import applet package
public class Print1To10Num extends Applet
{
public void paint(Graphics g)
{
for(int i=1;i<=10;i++)
{
g.drawString(i+"",20,10*i); // display message on applet
try
{
Thread.sleep(100);
}
catch(InterruptedException e){}
}
}
}
/* <applet code=Print1To10Num.class height=300 width=250>
</applet>*/
OUTPUT
C:\>javac Print1To10Num.java
C:\>appletviewer Print1To10Num.java