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

📄 clockapplet.java

📁 这是本人开发的一个小时钟 主要涉及到java的多线程技术
💻 JAVA
字号:
public class ClockApplet extends CurrentTimeApplet implements Runnable
{
 //通过封装线程对象来创建线程
 private Thread thread=null;
 private boolean suspended=false;
 
 public void init()
  {
     super.init();
     thread=new Thread(this);
     thread.start();//与applet中的start()方法不一样
  }

//applet中的start()方法 让中的方法与线程的方法相结合
 public void start()
  {
   resume();
  }
 public void run()
  {
    while(true)
     {
        stillClock.repaint();
         
        try
          {
            thread.sleep(1000);
            waitForNotificationToResume();
          }
        catch(InterruptedException ex)
          {}
     }
  }

//处理挂起操作 原来的suspended方法禁用
private synchronized void waitForNotificationToResume() throws InterruptedException
{
  while(suspended)
       wait();
}

//applet 中的stop()方法
public void stop()
{
  suspend();
}

//applet 中的destroy()方法
public void destroy()
{
  thread=null;
}

//处理resume(唤醒)操作 原来的被禁止使用
public synchronized void resume()
{
  if(suspended)
     {
       suspended=false;
       notify();
     }
}

public synchronized void suspend()
{
 suspended=true;
}   

}

⌨️ 快捷键说明

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