- 论坛徽章:
- 0
|
import java.util.*;
import java.text.*;
import javax.swing.*;
import java.awt.event.*;
public class TM extends javax.swing.JFrame{
public TM(){
initComponents();
setTitle("简易时钟");
setBounds(200,200,300,60);
tm=new java.util.Timer(true);
tm.schedule(new java.util.TimerTask(){
public void run(){
DATE_S.setText(getTimer());
}
},0,1*1000);
}
public void initComponents(){
jpanel1 = new javax.swing.JPanel();
jlabel1 = new javax.swing.JLabel();
DATE_S = new javax.swing.JLabel();
addWindowListener( new java.awt.event.WindowAdapter(){
public void windowClosing(java.awt.event.WindowEvent evt){
exitForm(evt);
}
});
jpanel1.setBorder(new javax.swing.border.EtchedBorder());
jlabel1.setFont(new java.awt.Font("宋体", 0, 12));
jlabel1.setText("u5f53u524du65f6u95f4:");
jpanel1.add(jlabel1);
DATE_S.setFont(new java.awt.Font("宋体", 0, 12));
DATE_S.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jpanel1.add(DATE_S);
getContentPane().add(jpanel1);
pack();
}
public void exitForm(java.awt.event.WindowEvent evt){
System.exit(0);
}
public static void main(String arg[]){
new TM().show();
}
public String getTimer(){
java.util.Date dt=new java.util.Date();
java.text.SimpleDateFormat df=new java.text.SimpleDateFormat("yyyy年MM月dd日 hh:mm:ss");
String sd=df.format(dt);
return sd;
}
private javax.swing.JLabel DATE_S;
private javax.swing.JLabel jlabel1;
private javax.swing.JPanel jpanel1;
private java.util.Timer tm;
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/4357/showart_15672.html |
|