欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java Timer使用示例,javatimer示例,package cn.o

来源: javaer 分享于  点击 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
相关栏目:

用户点评