1 package kk; 2 import java.util.*; 3 import java.awt.EventQueue; 4 import java.text.DecimalFormat; 5 import java.text.SimpleDateFormat; 6 import java.util.Scanner; 7 import java.util.Timer; 8 import java.util.TimerTask; 9 10 import javax.swing.JOptionPane; 11 12 13 14 15 public class kk { 16 float sum; 17 String parten = "0.00";//为下一行代码初始化准备 18 DecimalFormat decimal = new DecimalFormat(parten);//创建一个类型为DecimalFormat类的对象decimal 19 String str; 20 static Timer timer = null; 21 static SimpleDateFormat df=new SimpleDateFormat("mm:ss"); //控制时间的格式类 22 long starttime; 23 long finishtime; 24 long duration; 25 long allduration; 26 public kk() 27 { 28 timer = new Timer(); 29 finishtime=System.currentTimeMillis(); 30 starttime=finishtime; 31 timer.schedule(new TimerTask() 32 { 33 public void run() { 34 finishtime=System.currentTimeMillis(); 35 duration=finishtime-starttime; 36 /* if(duration/1000==25&&summary<tishu) 37 { 38 JOptionPane.showMessageDialog(null, "答题时间已到。答题总题数为"+(dadui+dacuo)+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+(tishu-dadui-dacuo)+",答题使用时间:"+(allduration+duration)/1000+"秒。"); 39 frame.setVisible(false); 40 new 每天一练初级版题型选择(); 41 } 42 String str=df.format(new Date(duration)); 43 T7.setText(str);*/ 44 String str=df.format(new Date(duration)); 45 System.out.print(str); 46 } 47 }, 1000, 1000); 48 } 49 public static void main(String[] args) { 50 EventQueue.invokeLater(new Runnable() { 51 public void run() { 52 try { 53 kk window = new kk(); 54 Scanner qq=new Scanner(System.in); 55 } catch (Exception e) { 56 e.printStackTrace(); 57 } 58 } 59 }); 60 } 61 }