import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class count
{
public static void main(String args[])
{
watch w=new watch();
Thread t=new Thread(w);
t.start();
}
}
class watch extends JFrame implements Runnable
{
int hour,minute,second,t;
JLabel a=new JLabel();
public watch()
{
super("倒计时");
Container c=getContentPane();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(200,200);
c.setLayout(new BorderLayout());
c.add(a,"North");
//System.out.println(hour+":"+minute+":"+second);
show();
}
public void paint(Graphics g)
{
g.setColor(Color.magenta);
g.drawString(Integer.toString(hour),100,10);
g.drawString(Integer.toString(minute),100,13);
g.drawString(Integer.toString(second),100,16);
}
public void run()
{
hour=2;
minute=00;
second=00;
t=hour+minute+second;
boolean a=true;
while(a)
{ if(t==0)
a=false;
second--;
if(second==00)
{
minute--;
second=60;
}
else if(minute==00)
{
hour--;
minute=60;
}
repaint();
try{
Thread.sleep(1000);
}catch(InterruptedException e){e.toString();}
}
}
}
这个程序是我刚写的,但是结果不能在面板上显示(还不知道写得对不对),求各位高手指导下。谢谢!