java 計時器
          import java.awt.*;
          import java.awt.event.*;
          import javax.swing.*;


          public class Miao extends JFrame implements ActionListener
          {
           JButton button1;
           JButton button2;
           JTextField  tf;
           JPanel panel;
              Timer time;
              int shu=0;
              int miao=0;
              int minute=0;
              int hour;
              int day;
              int year;
              int century;
              JLabel label;
           

           /**
            * Method actionPerformed
            *
            *
            * @param e
            *
            */
            public Miao()
            {
             
             
             this.xian();
             this.addlistener();
             
            }
            public void xian()
            {
             panel = new JPanel();
             time         = new Timer(1,this);
             label = new JLabel("0");
             this.button1 = new JButton("開始");
             this.button2 = new JButton("停止");
             this.tf      = new JTextField(30);
             panel.add(label);
             System.out.println ("label-width"+this.label.getWidth()+"");
             System.out.println ("label-height"+this.label.getHeight()+"");
             panel.add(tf);
             panel.add(this.button1);
             panel.add(this.button2);
             this.getContentPane().add(panel);
             this.setBounds(200,20,350,350);
             this.setVisible(true);
             this.setTitle("計數器");
            }
            public void addlistener()
            {
             this.button1.addActionListener(this);
             this.button2.addActionListener(this);
               // time.addActionListener(this);
           
            }
           
           public void actionPerformed(ActionEvent e)
           {
            // TODO: Add your code heree.getSource()==this.button1
           
            if(e.getSource()==this.button1)
            {
             System.out.println ("開始");
             this.shu=0;
             this.miao=0;
             this.minute=0;
             this.hour=0;
             this.day=0;
             this.year=0;
             this.century=0;
             this.tf.setText(0+"");
             time.start();
                
            }
            if(e.getSource()==this.button2)
            {
             System.out.println ("停止");
             time.stop();
            }
            if(e.getSource()==time)
            {
           // System.out.println ("time");
            this.shu++;
           // System.out.println (shu);
           
           
             this.tf.setText(this.century+"世紀"+this.year+"年"+this.day+"日"+this.hour+":"+minute+":"+miao+":"+shu+"");
             //label.setText(shu+"");
             if(shu%100==0)
             {
              this.shu=0;
              this.miao++;
             // tf.setText(minute+":"+miao+":"+shu);
              System.out.println ("label-width"+this.label.getWidth()+"");
               System.out.println ("label-height"+this.label.getHeight()+"");
               if(this.miao%60==0)
               {
                this.miao=0;
                this.minute++;
                if(this.minute%60==0)
                {
                 this.minute=0;
                 this.hour++;
                 if(this.hour%24==0)
                 {
                  this.hour=0;
                  this.day++;
                  if(this.day%365==0)
                  {
                   this.year++;
                   this.day=0;
                   if(this.year%100==0)
                   {
                    this.year=0;
                    this.century++;
                   }
                  }
                 }
                }
                
               }
             }
           
            
            
            }
            
           }
           public static void main(String as[])
            {
             new Miao();
            }
          }

          posted on 2011-07-02 23:47 sanmao 閱讀(225) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 鲁山县| 垣曲县| 呈贡县| 明水县| 寻乌县| 正定县| 江口县| 九龙县| 犍为县| 旺苍县| 横山县| 丹江口市| 高清| 嫩江县| 德庆县| 汉阴县| 克拉玛依市| 南投市| 阳城县| 望奎县| 临安市| 五莲县| 年辖:市辖区| 前郭尔| 井陉县| 天全县| 林周县| 淮滨县| 尚志市| 革吉县| 武义县| 平山县| 浦城县| 广平县| 临沭县| 新津县| 图片| 鹤岗市| 射洪县| 福海县| 汤原县|