1.团队课程设计博客链接
http://www.cnblogs.com/ltykm/p/7063663.html
2.个人负责模块或任务说明
本人任务:定时器具体功能的实现
3.自己的代码提交记录截图
4.自己负责模块或任务详细说明
实现定时器倒计时开始,暂停,继续,隐藏,显示功能的实现以及通过键盘对相关功能的操作。
// 显示计时详细信息
void createTimeInfo() {
jpTimeInfo = new JPanel();
jpTimeInfo.setLayout(null);
jpTimeInfo.setBackground(new Color(154, 217, 250));
jpTimeInfo.setSize(1200, 100);
// 总秒数
labSetTime = new JLabel("计时总秒数 : ", JLabel.CENTER);
labSetTime.setFont(new Font("微软雅黑", 0, 20));
jpTimeInfo.add(labSetTime).setBounds(0, 10, 400, 80);
// 已过秒数
labPassTime = new JLabel("已过秒数 : ", JLabel.CENTER);
labPassTime.setFont(new Font("微软雅黑", 0, 20));
jpTimeInfo.add(labPassTime).setBounds(400, 10, 400, 80);
// 剩余秒数
labRemainTime = new JLabel("剩余秒数 : ", JLabel.CENTER);
labRemainTime.setFont(new Font("微软雅黑", 0, 20));
jpTimeInfo.add(labRemainTime).setBounds(800, 10, 400, 80);
jpSetting.add(jpTimeInfo).setBounds(0, 300, 1200, 100);
}
// 按钮监听
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnBegin) {
if (tfdHours.getText().equals("") || tfdHours.getText() == null || tfdMinutes.getText().equals("")
|| tfdMinutes.getText() == null || tfdSeconds.getText().equals("") || tfdSeconds == null) {
JOptionPane.showMessageDialog(null, "请完成倒计时设置", "提示", JOptionPane.PLAIN_MESSAGE);
} else {
showTime = Time.getSeconds(new Integer(tfdHours.getText()), new Integer(tfdMinutes.getText()),
new Integer(tfdSeconds.getText()));
setTime = showTime;
// 改变面板值
labTime.setText(Time.getTime(showTime));
labSetTime.setText("计时总秒数 : " + setTime);
tfdHours.setText("");
tfdMinutes.setText("");
tfdSeconds.setText("");
flag = true;
new Thread(this).start();
}
}
if (e.getSource() == btnPause) {
flag = false;
}
if (e.getSource() == btnContinue) {
flag = true;
new Thread(this).start();
}
if (e.getSource() == btnHidden) {
this.remove(jpShowTime);
repaint();
}
if (e.getSource() == btnShow) {
this.add(jpShowTime).setBounds(0, 400, 1200, 400);
repaint();
}
if (e.getSource() == btnExit) {
System.exit(-1);
}
}
public void run() {
while (true) {
if (showTime <= 0) {
JOptionPane.showMessageDialog(null, "时间到", "提示", JOptionPane.PLAIN_MESSAGE);
break;
}
// 判断暂停
if (!flag) {
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
showTime -= 1;
labTime.setText(Time.getTime(showTime));
labPassTime.setText("已过秒数 : " + (setTime - showTime));
labRemainTime.setText("剩余秒数 : " + showTime);
}
}
public void keyTyped(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_F8) {
if (tfdHours.getText().equals("") || tfdHours.getText() == null || tfdMinutes.getText().equals("")
|| tfdMinutes.getText() == null || tfdSeconds.getText().equals("") || tfdSeconds == null) {
JOptionPane.showMessageDialog(null, "请完成倒计时设置", "提示", JOptionPane.PLAIN_MESSAGE);
} else {
showTime = Time.getSeconds(new Integer(tfdHours.getText()), new Integer(tfdMinutes.getText()),
new Integer(tfdSeconds.getText()));
setTime = showTime;
// 改变面板值
labTime.setText(Time.getTime(showTime));
labSetTime.setText("计时总秒数 : " + setTime);
tfdHours.setText("");
tfdMinutes.setText("");
tfdSeconds.setText("");
flag = true;
new Thread(this).start();
}
} else if (e.getKeyCode() == KeyEvent.VK_F9) {
flag = false;
} else if (e.getKeyCode() == KeyEvent.VK_F10) {
flag = true;
new Thread(this).start();
} else if (e.getKeyCode() == KeyEvent.VK_F11) {
this.remove(jpShowTime);
repaint();
} else if (e.getKeyCode() == KeyEvent.VK_F12) {
this.add(jpShowTime).setBounds(0, 400, 1200, 400);
repaint();
}
}
public void keyReleased(KeyEvent e) {
}
}
}
public class Time {
public static String getTime(int seconds) {
Integer hours = seconds / 3600;
Integer minutes = seconds / 60;
Integer second = seconds % 60;
String time = "";
if (minutes >= 60)
minutes %= 60;
if (hours < 10)
time += "0" + hours + " : ";
else
time += hours + " : ";
if (minutes < 10)
time += "0" + minutes + " : ";
else
time += minutes + " : ";
if (second < 10)
time += "0" + second;
else
time += second;
return time;
}
public static Integer getSeconds(Integer hours, Integer minutes, Integer seconds) {
return hours * 3600 + minutes * 60 + seconds;
}
}
5.课程设计感想