import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
public class digi extends Applet implements ActionListener,Runnable
{
Button b1,b2;
String temp="";
Thread t;
int h,m,s;
public void init()
{s=0;h=0;m=0;
b1=new Button("start");
b2=new Button("stop");
b1.addActionListener(this);
b2.addActionListener(this);
add(b1);add(b2);
}
public void run()
{
try
{
for(; ;)
{
if(s<59)
{
s=s+1;
}
else
{
m+=1;
s=0;
}
if(m>59)
{
h+=1;
m=0;
}
if(h>24)
{
h=0;
}
if(h<10)
temp="0"+h;
else
temp=""+h;
if(m<10)
temp+=":0"+m;
else
temp+=":"+m;
if(s<10)
temp+=":0"+s;
else
temp+=":"+s;
Thread.sleep(1000);
repaint();
}
}
catch(Exception e)
{
}
}
public void actionPerformed(ActionEvent e)
{
String z=e.getActionCommand();
if(z.equals("start"))
{
t=new Thread(this);
t.start();
}
else
t.stop();
}
public void paint(Graphics g)
{
g.setFont(new Font("Comic sans ms",Font.BOLD,24));
g.drawString(temp,200,200);
temp="";
}
}
/*<Applet code=digi width=400 height=400>
</Applet>*/
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
public class digi extends Applet implements ActionListener,Runnable
{
Button b1,b2;
String temp="";
Thread t;
int h,m,s;
public void init()
{s=0;h=0;m=0;
b1=new Button("start");
b2=new Button("stop");
b1.addActionListener(this);
b2.addActionListener(this);
add(b1);add(b2);
}
public void run()
{
try
{
for(; ;)
{
if(s<59)
{
s=s+1;
}
else
{
m+=1;
s=0;
}
if(m>59)
{
h+=1;
m=0;
}
if(h>24)
{
h=0;
}
if(h<10)
temp="0"+h;
else
temp=""+h;
if(m<10)
temp+=":0"+m;
else
temp+=":"+m;
if(s<10)
temp+=":0"+s;
else
temp+=":"+s;
Thread.sleep(1000);
repaint();
}
}
catch(Exception e)
{
}
}
public void actionPerformed(ActionEvent e)
{
String z=e.getActionCommand();
if(z.equals("start"))
{
t=new Thread(this);
t.start();
}
else
t.stop();
}
public void paint(Graphics g)
{
g.setFont(new Font("Comic sans ms",Font.BOLD,24));
g.drawString(temp,200,200);
temp="";
}
}
/*<Applet code=digi width=400 height=400>
</Applet>*/
No comments:
Post a Comment
Please put your valuable comments & requests here