package 甲;

 import java.awt.Dimension;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
* This class is a simple JFrame implementation(实现) to explain how to display time
* dynamically(动态的) on the JSwing-based interface.
*/
@SuppressWarnings("serial")
public class 一 extends JFrame {
/*
* Variables
*/
private JPanel timePanel;
private JLabel timeLabel;
private JLabel displayArea;
private String DEFAULT_TIME_FORMAT = "GYYYY年MM月dd日 EEE HH时mm分ss秒SSS";
//G-公元
//YYYY-年份
//MM-月份
//dd-日期
//EEE-星期
//HH-小时
//mm-分钟
//ss-秒钟
//SSS-毫秒
private String time;
private int ONE_SECOND = 9;//9毫秒刷新一次 public 一() {
super("东八区");//标题栏文字
timePanel = new JPanel();
timeLabel = new JLabel("北京时间");
displayArea = new JLabel(); configTimeArea();
timePanel.add(timeLabel);
timePanel.add(displayArea);
this.add(timePanel);
this.setAlwaysOnTop(true); //窗口置顶
this.setResizable(false);//窗口大小固定
this.setDefaultCloseOperation(EXIT_ON_CLOSE);//可以单击X退出
this.setSize(new Dimension(300, 90));//窗口尺寸大小
this.setLocationRelativeTo(null);//窗口出现位置
this.setType(java.awt.Window.Type.UTILITY); //窗口在任务栏不显示
this.setUndecorated(false); //不显示标题栏
} /**
* 这个方法创建 a timer task 每秒更新一次 the time
*/
private void configTimeArea() {
Timer tmr = new Timer();
tmr.scheduleAtFixedRate(new JLabelTimerTask(), new Date(), ONE_SECOND);
} /**
* Timer task 更新时间显示区
*
*/
protected class JLabelTimerTask extends TimerTask {
SimpleDateFormat dateFormatter = new SimpleDateFormat(
DEFAULT_TIME_FORMAT); @Override
public void run() {
time = dateFormatter.format(Calendar.getInstance().getTime());
displayArea.setText(time);
}
} public static void main(String arg[]) {
一 timeFrame = new 一();
timeFrame.setVisible(true);
}
}

最新文章

  1. ASP.NET Core应用针对静态文件请求的处理[4]: DirectoryBrowserMiddleware中间件如何呈现目录结构
  2. Spring整合jdbc
  3. RIDE安装遇到的问题及解决方法
  4. Quartz.net(调度框架) 使用Mysql作为存储
  5. LNMP源码安装
  6. Oracle SQL 调优之 sqlhc
  7. 开源App之MyHearts(二)
  8. POJ 1477
  9. JUC回顾之-ThreadPoolExecutor的原理和使用
  10. sourcetree下回退
  11. day01 Java基础
  12. spring 配置属性的详细信息
  13. C#泛型回顾点滴
  14. [.NET] 一步步打造一个简单的 MVC 电商网站 - BooksStore(三)
  15. 覆盖ng-zorro样式(非style.scss)
  16. androidkiller连接模拟器并修改源码调试
  17. Magento 2 安装数据表
  18. vue使用vue-awesome-swiper及一些问题
  19. 【python】threadpool的内存占用问题
  20. H.264 SVC

热门文章

  1. WVS简单使用
  2. MyBatis操作指南-与Spring集成(基于注解)
  3. .NET 串口通信中断接收,包含0X1A(作为EOF)
  4. Asp.Net Razor中的Consistent Layout
  5. 关于Java运算中类型自动提升的问题
  6. Python常见的运行错误
  7. Java类WebServer及中间件拿webshell方法总结
  8. 自定义GUID类
  9. SQL 还原数据库
  10. viewport设置