sdatimer.java

来自「很好的UI界面源码..还有自己的输入法,可以更换风格.可以学习和使用」· Java 代码 · 共 71 行

JAVA
71
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package cn.sda.ui;import cn.sda.event.TimerTickEvent;import java.util.Timer;import java.util.TimerTask;/** * * @author Administrator */public class SDATimer {    private int interval = 1000;    private boolean enabled = false;    private TimerTickEvent onTick = null;    private Timer timer = null;    private TimerTask timertask = null;    public SDATimer() {    }    public boolean isEnabled() {        return enabled;    }    public void setEnabled(boolean enabled) {        if (onTick != null) {            this.enabled = enabled;            if (enabled) {                timer = new Timer();                timertask = new TimerTask() {                    public void run() {                        //时钟执行                        doOnTick();                    }                };                timer.schedule(timertask, interval, interval);            } else {                timertask.cancel();                timer.cancel();                timertask = null;                timer = null;            }        }    }    public int getInterval() {        return interval;    }    public void setInterval(int interval) {        this.interval = interval;    }    public void setOnTick(TimerTickEvent onTick) {        this.onTick = onTick;    }    private void doOnTick() {        if (onTick != null) {            onTick.Event();        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?