package com.lzw;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.util.Date;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import com.swtdesigner.SwingResourceManager;
public class Accutron extends JFrame implements Runnable {
private JLabel label;
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Accutron frame = new Accutron();
frame.setVisible(true);
new Thread(frame).start();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Accutron() {
super();
setResizable(false);
setAlwaysOnTop(true);
setTitle("北京时间:");
setBounds(100, 100, 196, 115);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
label = new JLabel();
label.setFont(new Font("微软雅黑", Font.BOLD, 24));
label.setForeground(Color.YELLOW);
label.setHorizontalTextPosition(SwingConstants.CENTER);
label.setHorizontalAlignment(SwingConstants.CENTER);
ImageIcon icon = new ImageIcon(getClass().getResource("background.jpg"));
label.setIcon(icon);
getContentPane().add(label, BorderLayout.CENTER);
}
@Override
public void run() {
while(true){
Date date=new Date();
String timeStr = String.format("%tH:%tM:%tS %tp", date,date,date,date);
label.setText(timeStr);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}