package Rong;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
public class TestStatus extends JFrame{
private static final long serialVersionUID = 1L;
JLabel status=new JLabel();
SimpleDateFormat s=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d;
public TestStatus(){
this.setTitle("状态栏中实时显示系统时间");
this.setSize(400, 400);
Dimension dim=Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation((dim.width-this.getWidth())/2, (dim.height-this.getHeight())/2);
this.setDefaultCloseOperation
(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
Timer timer = new Timer();
TimerTask tt = new TimerTask() {
public void run() {
d=new Date();
status.setText(" 当前时间:"+ s.format(d));//显示系统日期时间
status.setBorder(new LineBorder(Color.black, 1, false));//设置边框线
status.setHorizontalAlignment(SwingConstants.CENTER);//设置文字在状态中居中显示
}
};
timer.schedule(tt, 0, 1000);
this.getContentPane().add(status,BorderLayout.SOUTH);
}
public static void main(String args[]){
new TestStatus();
}
}
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
public class TestStatus extends JFrame{
}