📄 timecontrol.java
字号:
/**************************************************************************
* (C) Copyright 2008 by Tao Liuyuan and Zhang Shuitao. *
* All Rights Reserved. *
* *
* Project : KYPlayer *
* File : TimeControl.java *
* JDK version used : jdk1.6.0_u4 *
* Version : 1.00 *
* Created : 2008.7.6 by we *
*************************************************************************/
package MP3Player;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import javax.swing.Timer;
/**
* 时间控制条类
* @author we
*/
public class TimeControl extends ControlBar {
/**
* 自动生成的序列化值
*/
private static final long serialVersionUID = 1L;
/**
* 负责的窗口
*/
private MainPlayer mainForm;
/**
* 播放计时器
*/
private Timer processTimer;
/**
* 构造函数
* @param mainFrame
*/
public TimeControl(MainPlayer mainFrame) {
super();
this.mainForm = mainFrame;
//每秒更新一次状态
processTimer = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setCurrentPercent();
}
});
}
/**
* 启动计时器
*/
public void start() {
processTimer.start();
if(mainForm.getPlayerStates() == 0) {
processTimer.stop();
}
}
/**
* 暂停计时器
*/
public void stop() {
processTimer.stop();
}
/**
* 设置当前进度比例
*/
public void setCurrentPercent() {
setProcessPercent((double) this.mainForm.getCurrentNanoseconds()
/ (double) this.mainForm.getTotaNanoseconds());
repaint();
mainForm.setTimeLabel("");
}
/**
* 设置完成后需要执行的函数
*/
@Override
public void done() {
super.done();
mainForm.setTime();
mainForm.setTimeLabel("");
}
/**
* 设置提示
*/
@Override
public void setTip(MouseEvent e) {
int percent = getPointerPostion(e);
setToolTipText("时间:" + Integer.toString(percent) + "%");
}
/**
* 重载的点击响应函数
*/
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
stop();
}
/**
* 重载的拖放完毕后响应函数
*/
@Override
public void mouseReleased(MouseEvent e) {
super.mouseReleased(e);
start();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -