java Timer使用示例,javatimer示例,package cn.o
分享于 点击 47439 次 点评:200
java Timer使用示例,javatimer示例,package cn.o
package cn.outofmemory.snippets.desktop;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JFrame;import javax.swing.Timer;public class Counter { private static int cnt; public static void main(String args[]) { new JFrame().setVisible(true); ActionListener actListner = new ActionListener() { @Override public void actionPerformed(ActionEvent event) { cnt += 1; System.out.println("Counter = "+cnt); } }; Timer timer = new Timer(500, actListner); timer.start(); }}
输出:
Counter = 1Counter = 2Counter = 3Counter = 4Counter = 5Counter = 6Counter = 7Counter = 8Counter = 9Counter = 10Counter = 11Counter = 12Counter = 13Counter = 14
用户点评