ZKX's LAB

JAVA 编写时钟程序 用java编写时钟的参考文献

2020-07-25知识9

JAVA 编写时钟程序 分太少了啊给你一个只实现了时钟的面板。import java.util.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;import javax.swing.Timer;public class Clock extends JFrame implements ActionListener{private static final long serialVersionUID=6790815213225162093L;Timer timer;int x,y,old_X,old_Y,r,x0,y0,w,h,ang;int sdo,mdo,hdo,old_M,old_H;TimeZone tz=TimeZone.getTimeZone(\"JST\");final double RAD=Math.PI/180.0;public Clock(){super(\"时钟\");setSize(300,300);setBackground(new Color(0,0,192));setResizable(false);Dimension scr=Toolkit.getDefaultToolkit().getScreenSize();Dimension fra=this.getSize();if(fra.width>;scr.width){fra.width=scr.width;}if(fra.height>;scr.height){fra.height=scr.height;}this.setLocation((scr.width-fra.width)/2,(scr.height-fra.height)/2);setVisible(true);int delay=1000;ActionListener taskPerformer=new ActionListener(){public void actionPerformed(ActionEvent evt){repaint();}};new Timer(delay,taskPerformer).start();}public void actionPerformed。用java编写时钟 求高人解释下每一行的意思。谢谢!!! package Clock;打包语句import javax.swing.*;引入此包下的JFrame,JLabel类等import java.awt.*;引入此包下的Frame,Label类等import java.util.*;引入此包下的Date类import java.text.*;引入此包下的SimpleTimeFormat类class Clock extends Thread {/创建一个线程名为ClockClockTest c;持有表盘的引用Clock(ClockTest c){/构造方法this.c=c;得到表盘}public void run(){while(true){/无限循环,即线程每睡一秒后执行一次setText()方法try {/try语句Thread.sleep(1000);睡1000毫秒,即1秒} catch(InterruptedException e){/捕获InterruptedException异常e.printStackTrace();打印出此异常}SimpleDateFormat dateformat=new SimpleDateFormat(\"hh:mm:ss\");得到一个格式化时间的对象dateformatString s=dateformat.format(new Date());dateformat对象将当前系统的时间格式化为hh:mm:ss形式,即十二小时制格式c.clock.setText(s);在表盘c上的clock标签内容,设置成当前的时间,1秒刷新一次,即认为时间在“走动”}}}public class ClockTest extends JFrame {/构造一个显示时钟的模板JFrame,称之为表盘JLabel clock;声明一个clock标签public ClockTest。写一个时钟的java类 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950public class A { public static void main(String[]args){ 7a686964616fe59b9ee7ad9431333337616535Clock clock=new Clock(13,20,38);System.out.print(clock);} } class Clock { private int hour;private int minute;private int second;public Clock(int hour,int minute,int second){ super();this.hour=hour;this.minute=minute;this.second=second;} public int getHour(){ return hour;} public void setHour(int hour){ this.hour=hour;} public int getMinute(){ return minute;} public void setMinute(int minute){ this.minute=minute;} public int getSecond(){ return second;} public void setSecond(int second){ this.second=second;}@Override public String toString(){ return\"现在时间是:\"+hour+\"时\"+minute+\"分\"+second+\"秒.;} }需要用java编写日历或时钟源代码, 时钟-import java.awt.*;import java.awt.event.*;import java.util.*;这两个包你没有导入 至少在你贴进来的代码中没有导入import java.text.SimpleDateFormat;public class test extends Frame implements Runnable{private Label Labelshow=new Label();private Panel pan1=new Panel();public test(){super(\"time\");setup();setResizable(false);设置此图形界面是不可以改变大小的setBounds(400,200,200,400);add(pan1);修改1 你没有添加Panel界面会什么都不显示的pack();setVisible(true);}public void setup(){pan1.add(Labelshow);Thread thread1=new Thread(this);修改2 Panel没有实现Runnable接口 不能用做线程启动的thread1.start();}public void run(){while(true){SimpleDateFormat sdf=new SimpleDateFormat(\"hh:mm:ss\");Labelshow.setText(sdf.format(new Date()));try{Thread.sleep(1000);}catch(Exception e){Labelshow.setText(\"出错错误,请重启程序\");}}}public static void main(String[]args){test te=new test();}}用java编写一个时钟程序 public class Time{static public void Xunhuan(){String sendtime=new SimpleDateFormat(\"hh:mm:ss\").format(new Date());时间格式System.out.println(sendtime);Thread.sleep(5000);每隔5秒打印一次(括号的数可改)xunhuan();}}用java编写一个时钟的程序 java.tanzhoujiaoyu.com java 免费教程 0基础入门到精通-在线免费直播公开课 java 大型免费直播公开课,行业大咖免费在线直播分享。内容包括 java,javaweb,java ja。.

#display#simpledateformat

随机阅读

qrcode
访问手机版