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

📄 clock.java

📁 Java钟表 用Java写的在网页上显示钟表的小程序,使用时需要自行编写html代码
💻 JAVA
字号:
// Clock.java: Show a running clock on the panel
import java.util.*;

public class Clock extends StillClock implements Runnable
{
  // Declare a thread for running the clock
  private Thread thread = null;

  // Determine if the thread is suspended
  private boolean suspended = false;

  // Default constructor
  public Clock()
  {
    this(Locale.getDefault(), TimeZone.getDefault());
  }

  // Construct a clock with specified locale and time zone
  public Clock(Locale locale, TimeZone timeZone)
  {
    super(locale, timeZone);

    // Create the thread
    thread = new Thread(this);

    // Start the thread
    thread.start();
  }

  // Implement the run() method to dictate what the thread will do
  public void run()
  {
    while (true)
    {
      repaint();
      try
      {
        thread.sleep(1000);
        waitForNotificationToResume();
      }
      catch (InterruptedException ex)
      {
      }
    }
  }

  // Wait for notification to resume
  private synchronized void waitForNotificationToResume()
    throws InterruptedException
  {
    while (suspended)
      wait();
  }

  // Resume the clock
  public synchronized void resume()
  {
    if (suspended)
    {
      suspended = false;
      notify();
    }
  }

  // Suspend the clock
  public synchronized void suspend()
  {
    suspended = true;
  }
}

⌨️ 快捷键说明

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