📄 example9_18.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.Timer;
public class Example9_18
{
public static void main(String args[])
{ TimeWin win= new TimeWin();
}
}
class TimeWin extends Frame implements ActionListener
{ TextField text;
Button bStart,bStop,bContinue;
Timer time;int n=0,start=1;
TimeWin()
{ time=new Timer(1000,this);
text=new TextField(10);
bStart=new Button("开始计时");
bStop=new Button("暂停计时");
bContinue=new Button("继续计时");
bStart.addActionListener(this);
bStop.addActionListener(this);
bContinue.addActionListener(this);
setLayout(new FlowLayout());
add(bStart);add(bStop);add(bContinue);add(text);
setVisible(true);
setSize(500,500);
validate();
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ setVisible(false);
}
}
);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==time)
{
java.util.Date date=new java.util.Date();
String str=date.toString().substring(11,19);
text.setText("时间"+str);
int x=text.getBounds().x;
int y=text.getBounds().y;
y=y+2;
text.setLocation(x,y);
}
else if(e.getSource()==bStart)
{
time.start();
}
else if(e.getSource()==bStop)
{
time.stop();
}
else if(e.getSource()==bContinue)
{
time.restart();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -