Java课程设计-定时器(团队)

时间:2024-01-17 13:04:08

一、团队介绍(没头脑和不高兴)

  • 陈文俊[组长] 201521123047 网络1512 宣委

Java课程设计-定时器(团队)

  • 郑子熙 201521123045 网络1512

Java课程设计-定时器(团队)

二、项目Git链接

定时器

三、项目git提交记录截图

Java课程设计-定时器(团队)

四、项目功能架构图与主要功能流程图

Java课程设计-定时器(团队)

五、项目运行截图

界面

Java课程设计-定时器(团队)

输入时间

Java课程设计-定时器(团队)

运行一段时间后暂停

Java课程设计-定时器(团队)

隐藏倒计时面板

Java课程设计-定时器(团队)

六、程序关键代码

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;
}
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) {
}
}

七、尚待改进或者新的想法

界面可以花时间做得更加美观,还用图标来代替按钮。

八、团队成员任务分配,团队成员课程设计博客链接(以表格形式呈现),标明组长。

姓名 学号 任务分配 博客地址
陈文俊[组长] 201521123047 框架构建、时间设置面板、倒计时面板、按钮设置 博客地址
郑子熙 201521123045 main函数的编写、负责TIme函数的编写、用于计算时间、按钮功能的实现 博客地址