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.*;
/**/
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
Replies
-
Manish Goyalnice code mohit
:clap::clap: -
Morningdot HabluThanks goyal...!!
-
sushant005hello CEans here is my code for digital watch,
Execute and see is it working fine or need some correction or any implementation.
I have not use any predefined method.
import java.awt.*;
import java.util.*;
import java.applet.*;
public class watch extends Applet implements Runnable
{
Thread t;
int i,j,k;
public void init()
{
setBackground(Color.red);
}
public void start()
{
t=new Thread(this);
t.start();
}
public void run()
{
for( i=0;i<24;i++)
for(j=0;j<60;j++)
for(k=0;k<60;k++){
try{
repaint();
Thread.sleep(1000);
}
catch(Exception e){}
}
}
public void paint(Graphics g)
{
String s=String.valueOf(j);
String t=String.valueOf(i);
String h=String.valueOf(k);
g.drawString(h,80,30);
g.drawString(" : ",70,30);
g.drawString(s,60,30);
g.drawString(" : ",50,30);
g.drawString(t,35,30);
}
}
/**/
You are reading an archived discussion.
Related Posts
We often see petrol bunks carrying the sign, "Please switch offf your mobile phones".. How come the concept of EM waves pose a threat to petrol? 😕
I was wondering what all problems can be faced in boilers in biomass plants which use rice straw as primary fuel. As I am not sure of the chemical reactions(read...
The official website of CAT (Common Admission Test) has been hacked. If you try visiting the site using Firefox web browser; you will see the following error message -
"Reported...
Hello everyone
some of you have already gone through many interviews(technical/hr/mr). Can you suggest some of many and many other ceians queries.
1. Firstly tell about dressing style. Would wearing...
Hullo,
i am in third year. i want to do something worth while along with my B.E.Cse .. any courses ..or any projects or anything extra... i just need your...