Digital watch in java.
hello friend's
Just completed a program for a digital watch in java...Check out this code.
Command to compile this code: javac kk.java
Command to execute the class file created by compiler: appletviewer kk.java
Just completed a program for a digital watch in java...Check out this code.
import java.awt.*;save it as kk.java.
import java.applet.*;
/*<APPLET CODE="kk.class" HEIGHT=200 WIDTH=300></APPLET>*/
public class kk extends Applet implements Runnable
{
int x=00;
int y=00;
int z=00;
Thread t;
public void time()
{
if(x!=59)
{
x=x+1;
}
else
{
if(y!=59)
{
y=y+1;
x=00;
}
else
{
if(z!=59)
{
z=z+1;
y=00;x=00;
}
else
{
z=00;y=00;x=00;
}
}
}
}
public void init()
{
setBackground(Color.cyan);
}
public void start()
{
t=new Thread(this);
t.start();
}
public void run()
{
while(t!=null)
{
try
{
repaint();
t.sleep(1000);
time();
}
catch(InterruptedException e)
{
System.out.println("Thread interrupted ");
}
}
}
public void paint(Graphics g)
{
Font f=new Font("ARIEL",Font.BOLD+Font.ITALIC,60);
String p=Integer.toString(x);
String q=Integer.toString(y);
String r=Integer.toString(z);
setFont(f);
g.drawString(r+":"+q+":"+p,20,70);
showStatus(r+":"+q+":"+p);
}
}
Command to compile this code: javac kk.java
Command to execute the class file created by compiler: appletviewer kk.java
0