📄 bscountdown.java
字号:
package edu.ou.kmi.buddyspace.plugins.conference.gui;
/*
* BSCountdown.java
*
* Project: BuddySpace
* (C) Copyright Knowledge Media Institute 2002
*
*
* Created on 29 October 2002, 8:43
*/
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import org.jabber.jabberbeans.util.*;
import edu.ou.kmi.buddyspace.plugins.conference.core.*;
/**
* <code>BSCountdown</code> is the conference countdown, which automatically
* send coundown messages into conference room. It uses
* <code>javax.swing.Timer</code>.
*
* @author Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
*/
public class BSCountdown implements ActionListener {
protected String name;
protected int timeLeft;
protected int curStep;
protected javax.swing.Timer timer = null;
protected Vector listeners = null;
// thresholds in seconds for changing of countdown frequency
public static int[] changeFreqTimes = {60, 30, 10, 5};
// steps in seconds - must have changeFreqTimes.length+1 values
public static int[] steps = {60, 30, 20, 5, 1};
/**
* Constructor.
*/
public BSCountdown(String name, int minutes, int seconds) {
this.name = name;
this.timeLeft = minutes * 60 + seconds;
listeners = new Vector();
curStep = getNextStep();
timer = new javax.swing.Timer(curStep * 1000, this);
timer.setRepeats(false);
}
/** Returns length of next timer step */
protected int getNextStep() {
if (timeLeft <= 0) return 0;
int curFreqIndex = 0;
// finds the interval it's in
for (int i=0; i < changeFreqTimes.length; i++)
if (timeLeft <= changeFreqTimes[i])
curFreqIndex = i+1;
int step = steps[curFreqIndex];
// aligns to whole steps
int alignedTime = (timeLeft/step) * step;
if (alignedTime != timeLeft)
step = timeLeft - alignedTime;
// aligns to the end of interval
if (curFreqIndex < changeFreqTimes.length &&
timeLeft - step < changeFreqTimes[curFreqIndex])
step = timeLeft - changeFreqTimes[curFreqIndex];
return step;
}
public void start() {
timer.start();
}
public void stop() {
timer.stop();
}
/** Returns time left */
public int getTimeLeft() {
return timeLeft;
}
public String getName() {
return name;
}
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == timer) {
timeLeft = timeLeft - curStep;
curStep = getNextStep();
if (curStep != 0) {
timer.setDelay(curStep*1000);
timer.setInitialDelay(curStep*1000);
timer.restart();
}
else {
timer.removeActionListener(this);
}
fireActionPerformed(new ActionEvent(this, evt.getID(),
evt.getActionCommand(), evt.getModifiers()));
}
}
public void addActionListener(ActionListener listener) {
if (listener == null) return;
if (!listeners.contains(listener))
listeners.add(listener);
}
public void removeActionListener(ActionListener listener) {
if (listener == null) return;
listeners.remove(listener);
}
protected void fireActionPerformed(ActionEvent e) {
Enumeration ls = listeners.elements();
while (ls.hasMoreElements()) {
ActionListener l = (ActionListener) ls.nextElement();
l.actionPerformed(new ActionEvent(this, e.getID(), e.getActionCommand()));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -