團隊博客地址html
按鈕設置java
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.建立倒計時面板、設置時間面板、倒計時屬性面板、時間信息面板this
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); }
雖然時間緊迫,可是作了組長仍是要負責好課設,因而和組員一直討論要怎麼搞纔好,溝通交流是作課設最主要的,分配好各自的工做而後討論交流才讓咱們的課設最終完成。最後的最後,不懂的~要百度~