如何解决秒表精度?
import java.awt.*;import java.awt.event.*;
class Demo extends Canvas implements Runnable
{
int f1=0,f2=0,m1=0,m2=0,hm1=0,hm2=0;//f1,f2,m1,m2,hm1,hm2分别用来当00:00:00 f1f2:m1m2:hm1hm2
static Demo demo; //公共Demo
int pi=0; //用来当开关
Frame frame = new Frame();
public void ini()
{
setSize(800,600);
frame.setSize(800,600);
frame.add(this);
frame.setVisible(true);
this.addMouseListener(
new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
pi=(pi+1)%2;
if(pi==1)
{
Thread tt = new Thread(demo);
tt.setName("li");
tt.setPriority(1);
tt.start();
}
}
}
);
}
public void run()
{
while(pi!=0)
{
try
{
Thread.sleep(10);
}
catch(Exception e)
{
}
System.out.println(f1+""+f2+":"+m1+""+m2+":"+hm1+""+hm2);
++hm2;
if(hm2==10)
{
++hm1;
hm2=0;
if(hm1==10)
{
++m2;
hm1=0;
if(m2==10)
{
++m1;
m2=0;
if(m1==6)
{
++f2;
m1=0;
if(f2==10)
{
++f1;
f2=0;
if(f1==6)
{
f1=0;
}
}
}
}
}
}
}
}
public static void main(String[] ager)
{
demo = new Demo();
demo.ini();
}
}