?? clockpanel.java.bak
字號:
//********************************************************************
// ClockPanel.java Author: 鐘凱藝
//
// 為左pp8.10跑表的時間顯示寫的
//********************************************************************
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ClockPanel extends JPanel
{ private int count;
private JButton clockButton;
private JButton ZeroButton;
private JLabel label;
private int flag = 1;
private JLabel Label;
private Timer timer;
private final int DELAY = 16;
//-----------------------------------------------------------------
// Constructor: Sets up the main GUI components.
//-----------------------------------------------------------------
public ClockPanel()
{ count = 0;
clockButton = new JButton ("啟動");
clockButton.addActionListener (new ButtonListener());
label = new JLabel (" ");
ZeroButton = new JButton ("清零");
ZeroButton.addActionListener (new ZeroListener());
add (clockButton);
add (ZeroButton);
add (label);
setPreferredSize (new Dimension(300, 75));
setBackground (Color.yellow);
}
private class ButtonListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
if(flag == 1)
{
clockButton.setText("停止");
timer = new Timer(DELAY, new ClockListener());
timer.start();
flag = 0;
}
else
{
clockButton.setText("啟動");
timer.stop();
flag = 1;
}
}
}
private class ClockListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
count++;
label.setText((count/3600)%60+"分"+(count/60)%60+"秒"+count%60);
repaint();
}
}
private class ZeroListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
timer.stop();
label.setText("0分0秒");
clockButton.setText("重新啟動");
repaint();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -