Java课程设计-定时器

Java课程设计--定时器


1.团队课程设计博客链接

团队博客地址

2.个人负责模块或任务说明

  • 框架构建
  • 时间设置面板,倒计时面板
  • 按钮设置

3.自己的代码提交记录截图

4.自己负责模块或任务详细说明

1.框架构建

public TimeFrame() {
		add(new TimePanel());

		this.setTitle("定时器");
		this.setSize(1200, 800);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		this.setVisible(true);
	}

2.创建类

class TimePanel extends JPanel implements ActionListener, KeyListener, Runnable {

		/**
		 * 
		 */
     	private static final long serialVersionUID = 1L;
     	
		private int setTime;
		private int showTime;
		// 定义是否计时变量
		private boolean flag = false;
		private JPanel jpShowTime, jpSetting, jpTimeInfo;

		private JLabel labTime, labSetTime, labPassTime, labRemainTime;
		private JButton btnBegin;
		private JButton btnPause;
		private JButton btnContinue;
		private JButton btnHidden;
		private JButton btnShow;
		private JButton btnExit;
		// 倒计时设置
		private JPanel jpTimeSetting;
		private JTextField tfdHours;
		private JTextField tfdMinutes;
		private JTextField tfdSeconds;

		public TimePanel() {
			this.setSize(1200, 800);
			this.setLayout(null);

			createSetting();
			createShowTime();
			
			jpSetting.addKeyListener(this);
			jpSetting.setFocusable(true);
		}

3.创建倒计时面板、设置时间面板、倒计时属性面板、时间信息面板

void createShowTime() {
			jpShowTime = new JPanel();
			jpShowTime.setSize(1200, 400);
			jpShowTime.setBackground(Color.BLACK);

			labTime = new JLabel("00 : 00 : 00", JLabel.CENTER);
			labTime.setFont(new Font("微软雅黑", 1, 200));
			labTime.setForeground(Color.RED);
			jpShowTime.add(labTime);

			add(jpShowTime).setBounds(0, 400, 1200, 400);

		}
void createSetting() {
			jpSetting = new JPanel();
			jpSetting.setSize(1200, 400);
			jpSetting.setLayout(null);

			createTimeSetting();
			createTimeInfo();

			// 开始按钮
			btnBegin = new JButton("开始[F8]");
			jpSetting.add(btnBegin).setBounds(700, 50, 80, 50);
			// 暂停按钮
			btnPause = new JButton("暂停[F9]");
			jpSetting.add(btnPause).setBounds(800, 50, 80, 50);
			// 继续按钮
			btnContinue = new JButton("继续[F10]");
			jpSetting.add(btnContinue).setBounds(900, 50, 80, 50);
			// 隐藏按钮
			btnHidden = new JButton("隐藏[F11]");
			jpSetting.add(btnHidden).setBounds(700, 120, 80, 50);
			// 显示按钮
			btnShow = new JButton("显示[F12]");
			jpSetting.add(btnShow).setBounds(800, 120, 80, 50);
			// 帮助按钮
			btnExit = new JButton("退出");
			jpSetting.add(btnExit).setBounds(900, 120, 80, 50);

			btnBegin.addActionListener(this);
			btnPause.addActionListener(this);
			btnContinue.addActionListener(this);
			btnHidden.addActionListener(this);
			btnShow.addActionListener(this);
			btnExit.addActionListener(this);

			add(jpSetting).setBounds(0, 0, 1200, 400);
		}
void createTimeSetting() {
			jpTimeSetting = new JPanel();
			jpTimeSetting.setSize(300, 200);
			jpTimeSetting.setLayout(new FlowLayout());

			jpTimeSetting.add(tfdHours = new JTextField(3));
			jpTimeSetting.add(new JLabel("时"));
			jpTimeSetting.add(tfdMinutes = new JTextField(3));
			jpTimeSetting.add(new JLabel("分"));
			jpTimeSetting.add(tfdSeconds = new JTextField(3));
			jpTimeSetting.add(new JLabel("秒"));
			
			tfdHours.addKeyListener(this);
			tfdMinutes.addKeyListener(this);
			tfdSeconds.addKeyListener(this);

			jpSetting.add(jpTimeSetting).setBounds(100, 100, 300, 200);
		}
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);
		}

5.课程设计感想

虽然时间紧迫,但是做了组长还是要负责好课设,于是和组员一直讨论要怎么搞才好,沟通交流是做课设最主要的,分配好各自的工作然后讨论交流才让我们的课设最终完成。最后的最后,不懂的~要百度~
posted @ 2017-06-22 16:22  陈大家  阅读(493)  评论(0编辑  收藏  举报