java学习笔记--------显示时间

来源:互联网 发布:macbookpro办公软件 编辑:程序博客网 时间:2024/06/04 18:50

显示时间的方法很多,这里的方法比较简单,代码如下:

package Testing3;import javax.swing.*;import javax.swing.Timer;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.*;public class Testing3 {JFrame jf = new JFrame();JLabel jl ;//注意使用的是javax.swing的Timer//该Timer可以定时处理Action事件Timer t;//定义Timer要处理的事件ActionListener timeActionListener = new ActionListener(){public void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubjl.setText(Calendar.getInstance().getTime().toString());}};public Testing3(){jl = new JLabel(Calendar.getInstance().getTime().toString());//定义完整   并启动t = new Timer(1000,timeActionListener);t.start();jf.add(jl);jf.pack();jf.setVisible(true);}public static void main(String[] args) {// TODO Auto-generated method stubTesting3 test = new Testing3();}}

效果:


原创粉丝点击