返回列表 發帖
  1. package bbs.istak.org.tw;

  2. import java.awt.BorderLayout;
  3. import java.awt.EventQueue;
  4. import java.util.Calendar;

  5. import javax.swing.JFrame;
  6. import javax.swing.JPanel;
  7. import javax.swing.border.EmptyBorder;
  8. import javax.swing.JLabel;

  9. public class clock extends JFrame {

  10.         private JPanel contentPane;

  11.         /**
  12.          * Launch the application.
  13.          */
  14.         public static void main(String[] args) {
  15.                 EventQueue.invokeLater(new Runnable() {
  16.                         public void run() {
  17.                                 try {
  18.                                         clock frame = new clock();
  19.                                         frame.setVisible(true);
  20.                                 } catch (Exception e) {
  21.                                         e.printStackTrace();
  22.                                 }
  23.                         }
  24.                 });
  25.         }

  26.         /**
  27.          * Create the frame.
  28.          */
  29.         public clock() {
  30.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  31.                 setBounds(100, 100, 164, 128);
  32.                 contentPane = new JPanel();
  33.                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  34.                 setContentPane(contentPane);
  35.                 contentPane.setLayout(null);
  36.                
  37.                 JLabel lblNewLabel = new JLabel("New label");
  38.                 lblNewLabel.setBounds(10, 10, 128, 70);
  39.                 contentPane.add(lblNewLabel);
  40.                
  41.                 Calendar c = Calendar.getInstance();
  42.                
  43.                 SDF sdf = new SDF("yyyy/MM/dd hh:mm:ss");
  44.                 lblNewLabel.setText(sdf.format(c));
  45.         }
  46. }
複製代碼

TOP

  1. package bbs.istak.org.tw;

  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;

  4. import javax.swing.JLabel;

  5. public class TThread extends Thread{
  6.        
  7.         private JLabel label;
  8.        
  9.         public TThread(JLabel label)
  10.         {
  11.                
  12.                 this.label = label;
  13.                
  14.         }
  15.        
  16.         public void run()
  17.         {
  18.                 while(true)
  19.                 {
  20.                        
  21.             try {
  22.                     Date d = new Date();
  23.                     SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 E aH時mm分ss秒");
  24.                     label.setText(sdf.format(d));
  25.                                 Thread.sleep(1000);
  26.                         } catch (InterruptedException e) {
  27.                                 // TODO 自動產生的 catch 區塊
  28.                                 e.printStackTrace();
  29.                         }                
  30.                        
  31.                 }
  32.                        
  33.         }

  34. }
複製代碼
  1. package bbs.istak.org.tw;

  2. import java.awt.BorderLayout;
  3. import java.awt.EventQueue;
  4. import java.util.Calendar;

  5. import javax.swing.JFrame;
  6. import javax.swing.JPanel;
  7. import javax.swing.border.EmptyBorder;
  8. import javax.swing.JLabel;

  9. public class Clock extends JFrame {

  10.         private JPanel contentPane;
  11.         private JLabel time;

  12.         /**
  13.          * Launch the application.
  14.          */
  15.         public static void main(String[] args) {
  16.                 EventQueue.invokeLater(new Runnable() {
  17.                         public void run() {
  18.                                 try {
  19.                                         Clock frame = new Clock();
  20.                                         frame.setVisible(true);
  21.                                 } catch (Exception e) {
  22.                                         e.printStackTrace();
  23.                                 }
  24.                         }
  25.                 });
  26.         }

  27.         /**
  28.          * Create the frame.
  29.          */
  30.         public Clock() {
  31.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  32.                 setBounds(100, 100, 315, 128);
  33.                 contentPane = new JPanel();
  34.                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  35.                 setContentPane(contentPane);
  36.                 contentPane.setLayout(null);
  37.                
  38.             time = new JLabel("New label");
  39.                 time.setBounds(10, 10, 279, 70);
  40.                 contentPane.add(time);
  41.                 Gettime();
  42.                
  43.         }
  44.        
  45.         public void Gettime(){
  46.                
  47.                 TThread tt = new TThread(time);
  48.                 tt.start();
  49.         }




  50.        
  51. }
複製代碼

TOP

返回列表