//show.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.*;
import java.util.*;
public class show extends JFrame implements Runnable
{
?static JFrame jf;
?JLabel jl;
?public show()
?{
??jf=new JFrame("時間顯示");
??jl=new JLabel();
??jf.getContentPane().add(jl);
??jf.setSize(200,100);??
?}
?
?public void run()
?{
??while(true)
??{
???SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
???jl.setText(sdf.format(new Date()));
???try
???{
????Thread.sleep(1000);?
???}
???catch(Exception e)
???{
????jl.setText("出錯錯誤,請重啟程序");
???}
??}??
?}?
?public static void main(String arg[])
?{
??show t=new show();
??Thread thread1=new Thread(t);
??thread1.start();??
??jf.setVisible(true);??
?}?
}

posted on 2007-01-16 15:43
楊彩 閱讀(5385)
評論(3) 編輯 收藏 所屬分類:
我的Java程序