⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clocks.java

📁 这里一个用java写成的时钟的程序,从系统标准时间中读取目前准确时间,并用用户界面显示,有时针,分针,秒针的走动显示.
💻 JAVA
字号:
import java.applet.*;
import java.awt.*;
import java.util.Date;
import java.text.DateFormat;

//This applet displays the time and updates it every second.
public class Clocks extends Applet implements Runnable 
{
	Label time;                //A component to display the time.
	DateFormat timeFormat;     //This object converts time to a string.
	Thread timer;              //The thread that updates the time.
	volatile boolean running;  //A flag used to stop the thread.
 public void init(){
	 time=new Label();
	 time.setFont(new Font("helvetica",Font.BOLD,12) );
	 time.setAlignment(Label.CENTER);
	 setLayout(new BorderLayout() );
	 add(time,BorderLayout.CENTER);
	 timeFormat=DateFormat.getTimeInstance(DateFormat.MEDIUM);
 }
 public void start(){
	 running=true;
	 if (timer==null)
	 {  timer=new Thread(this);
	    timer.start();
	 }
 }
 public void run(){
	 while (running)
	 {  time.setText(timeFormat.format(new Date() ));
	    try
	    {
	    	Thread.sleep(1000);
	    }
	    catch (InterruptedException e)
	    {
	    }
	 }
	 timer=null;
 }
 public void stop(){
	running=false;
 }
 public String getAppletInfo(){
	 return "Clock applet";
 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -