java 計(jì)時(shí)器
          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("計(jì)數(shù)器");
            }
            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+"世紀(jì)"+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 閱讀(223) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 胶南市| 朝阳区| 奉节县| 高阳县| 永康市| 正镶白旗| 手游| 东安县| 大洼县| 图片| 堆龙德庆县| 房产| 黄冈市| 云林县| 天柱县| 沁水县| 哈巴河县| 鸡东县| 大埔县| 崇左市| 沽源县| 亳州市| 莎车县| 余江县| 天峨县| 九江市| 灵璧县| 柳林县| 木兰县| 蛟河市| 台南市| 衡南县| 临邑县| 乌拉特中旗| 渭源县| 岱山县| 鲜城| 化德县| 偃师市| 渝北区| 库车县|