MyTimer.zip

  • PUDN用户
    了解作者
  • Java
    开发工具
  • 104KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 1
    下载次数
  • 2015-06-16 10:46
    上传日期
time application to define your time elapse
MyTimer.zip
内容介绍
import javax.swing.Timer; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.text.DecimalFormat; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author Lefie */ public class Waktu extends javax.swing.JFrame implements ActionListener { Timer t; DecimalFormat df; /** * Creates new form Waktu */ public Waktu() { initComponents(); df=new DecimalFormat("00"); jLabel1.setText("Elapse : "+df.format(hour)+" : "+df.format(minute) +" : "+df.format(second)+" : "+df.format(csecond)); t =new Timer(10,this); //myTimer=new Timer(10,this); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText("jLabel1"); jButton1.setText("Start"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap()) .addGroup(layout.createSequentialGroup() .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 294, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addGap(18, 18, 18) .addComponent(jButton1) .addContainerGap(231, Short.MAX_VALUE)) ); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed if(isStart) { startTimer(); isStart=false; jButton1.setText("Stop"); } else { isStart=true; jButton1.setText("Start"); stopTimer(); } // TODO add your handling code here: }//GEN-LAST:event_jButton1ActionPerformed void startTimer() { t.start(); } void stopTimer() { t.stop(); csecond=0; second=0; minute=0; hour=0; } private int csecond=0; private int second=0; private int minute=0; private int hour=0; //private boolean isPause=true; private boolean isStart=true; public void actionPerformed(ActionEvent e){ csecond++; if(csecond==100) { second++; csecond=0; } if(second==60){ minute++; second=0; } if(minute==60){ hour++; minute=0; } jLabel1.setText("Elapse : "+df.format(hour)+" : "+df.format(minute) +" : "+df.format(second)+" : "+df.format(csecond)); } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Waktu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Waktu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Waktu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Waktu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Waktu().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; // End of variables declaration//GEN-END:variables }
评论
    相关推荐
    • time.rar
      Backwards compatible time call Device Driver for linux v2.13.6.
    • Time.zip
      Project transparent time for windows desktop.
    • timetimetime:InsTime时间
      欢迎来到TimeTimeTime TimeTimeTime是一个有关深度时间感知的时间团队项目,由Unicamp的Human Computer Interface 2018s1类的成员组成。 该项目基于 ,您可以输入有关我们如何组织自己来构建项目的很好的介绍。 ...
    • jquery-readingtime
      凉亭: bower install jquery-readingtime 用法 在任何元素上调用.readingtime() ,它返回一个整数,以分钟为单位估计阅读时间。 注意:当在多个元素上调用时,它计算集合中第一个元素的读取时间。 例子 单个元素...
    • partytime
      Partytime播客解析器 从播客索引中提取-https: 标识的命名空间元素-https: RSS Feed示例-https:
    • updatetime
      updatetime 傻瓜式启动时间同步服务器 适用于windows系统
    • time_component
      time_component 1、引入time_component.css和time_component.js文件; 2、调用createTimeDiv(table-element,col_name),即可; 3、btnOnClick里面处理提交请求操作。
    • geologic_time_scale.zip
      Geologic time scale and others
    • Price & Time.rar
      Price & Time Book
    • Time.rar
      SDG RHEAREHAH AE ERH