📄 shanjian.java
字号:
package zhican;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;
import java.util.Date;
import java.text.SimpleDateFormat;
class ClockFrame extends JFrame implements Runnable,WindowListener
{
private Thread timer=null;
private JLabel jLabel=null;
private SimpleDateFormat sdf=null;
private boolean go;
public ClockFrame()
{
super("时间");
sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date now=new Date();
jLabel=new JLabel(" "+sdf.format(now));
getContentPane().add(jLabel,BorderLayout.CENTER);
addWindowListener(this);
setSize(120,80);
setLocation(300,200);
go=true;
timer=new Thread(this);
timer.start();
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void run()
{
while(go)
{
try
{
timer.sleep(1000);
}catch(InterruptedException e){
e.printStackTrace();
}finally
{
jLabel.setText(" "+sdf.format(new Date()));
}
}
}
public void windowActivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowClosing(WindowEvent e){
go=false;
setVisible(false);
}
public void windowDeactivated(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowOpened(WindowEvent e){}
public static void main(String args[])
{
new ClockFrame().setVisible(true);
}
private void jbInit() throws Exception {
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -