Tuesday, 29 November 2016

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.

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
       catch(InterruptedException e){}
/*  <applet code=Print1To10Num.class height=300 width=250>


C:\>javac Print1To10Num.java
C:\>appletviewer Print1To10Num.java

No comments:

Post a Comment