java 计时器求助

爱飞的云 2016-08-29 06:29:27


想做一个类似于上图那样计时器 从00:00:00开始计时
但不知道怎么弄 毫无头绪。。。
...全文
114 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
爱飞的云 2016-08-29
  • 打赏
  • 举报
回复
谢谢各位啊 问题已解决
涛涛之海 2016-08-29
  • 打赏
  • 举报
回复
一是:初始化窗体,JFrame; 二是:时间的标准化格式,使其成为00:00:00; 三是:线程的使用,体现在窗体的实现,时间的获取并发调用。 步骤: public class Clock extends JFrame implements Runnable { //初始化窗体 JLabel I=new JLabel(); public Clock(){ this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//出现关闭口 this.setSize(250,200); this.add(I); this.setVisible(true); } //系统时间的格式化 public static String format(int number){ return number<10?"0"+number:""+number; } //获取系统的时间 public static String getTime(){ Calendar c=new GregorianCalendar(); int hour=c.get(Calendar.HOUR_OF_DAY); int min=c.get(Calendar.MINUTE); int second=c.get(Calendar.SECOND); return format(hour)+":"+format(min)+":"+format(second); } //开始调用 public static void main(String[] args) { Thread t=new Thread(new Clock()); t.start(); } //线程 @Override public void run() { // TODO Auto-generated method stub while(true){ try { Thread.sleep(1000);//单位是毫秒,睡眠1秒 } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } I.setText(getTime()); } } }
xw534 2016-08-29
  • 打赏
  • 举报
回复
写一个timer计时器,三个变量hh:mm:ss,一秒加1给变量赋值
rendason 2016-08-29
  • 打赏
  • 举报
回复
是画图形界面有问题还是不知道怎么算时间?

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧