level 5
代码如下:格式有点乱
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class myTest{
public static void main(String[]agrs)
{
jframe myJframe = new jframe();
myJframe.setVisible(true);
myJframe.setSize(500,400);
myJframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class jframe extends JFrame implements Runnable{
GregorianCalendar myTime = new GregorianCalendar();
Thread clock = new Thread(this);
JLabel jlabel;
public jframe()
{
super("数字时钟");
jlabel = new JLabel();
this.add(jlabel,BorderLayout.CENTER);
clock.start();
}
public void run(){
int time_hour,time_min,time_second;
for(;;)
{
time_hour = myTime.get(Calendar.HOUR_OF_DAY);
time_min = myTime.get(Calendar.MINUTE);
time_second = myTime.get(Calendar.SECOND);
//jlabel.setText(time_hour+":"+time_min+":"+time_second);
System.out.println(time_hour+":"+time_min+":"+time_second);
try
{
clock.sleep(1000);
}
catch(Exception e){
e.printStackTrace();
}
}
}}
2012年11月29日 03点11分
6
level 8
GregorianCalendar myTime = new GregorianCalendar();
你把这个定义在外边,循环的时候每次都是new的同一个对象。。。循环自然就是一样的了。。。你把这句话移到循环体里面去
2012年11月29日 03点11分
8
![[狂哭]](/static/emoticons/u72c2u54ed.png)
感谢 成功了
2012年11月29日 03点11分