下述法典正确地处理:(1) 要求调查组校对的任务,(2) 在任务需要时间超过延迟时,不要淹没调查组的read,(3) 停工时收集垃圾:
import android.os.Handler;
import android.os.Looper;
import java.util.ArrayList;
class ActionEvent {
public ActionEvent(Object src) {
}
}
interface ActionListener {
public void actionPerformed(ActionEvent e);
}
class Timer {
public Timer(int delay, ActionListener al) {
addActionListener(al);
_delay = delay;
}
public void addActionListener(ActionListener al) {
_listeners.add(al);
}
private void fireActionPerformed() {
for (ActionListener al : _listeners.toArray(new ActionListener[0])) {
al.actionPerformed(new ActionEvent(this));
}
}
private void fireAfterDelay() {
if (!_bStarted)
return;
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
public void run() {
if (_bStarted) {
fireActionPerformed();
if (_bStarted)
fireAfterDelay();
}
}
}, _delay);
}
public void start() {
if (!_bStarted) {
_bStarted = true;
fireAfterDelay();
}
}
public void stop() {
_bStarted = false;
}
private final ArrayList<ActionListener> _listeners = new ArrayList<>();
private int _delay;
private boolean _bStarted;
}
我在“行动”和“行动生活”课堂上,与Java Swing更加兼容。 简而言之,您可以删除“行动”一词,代之以可操作的“行动生计”。