actionupdater.java

来自「一款益智类的手机游戏」· Java 代码 · 共 58 行

JAVA
58
字号
package twplanegame;import java.util.*;class ActionUpdater extends TimerTask{   // list of all the listeners   private final ActionListener[]   m_listener = new ActionListener[20];   private final Timer              m_updateTimer = new Timer();   /**    * Creates a ActionUpdater object and starts it.    *    * @param initSleep Initial sleep time.    */   public ActionUpdater(int initSleep, int interval)   {      m_updateTimer.schedule(this, initSleep, interval);   }   /**    * Registers the ActionListener that should be informed of an action to be    * performed.    *    * @param listener The listener that should be informed of an action to be    * performed.    * @return true if it was registered; false otherwise    */   public boolean register(ActionListener listener)   {      // find an empty spot, and save the reference      for (int i = 0; i < m_listener.length; i++)      {         if (m_listener[i] == null)         {            m_listener[i] = listener;            return true;         }      }      return false;   }   /**    * Perform the repetition of the key.    */   public void run()   {      // ask each listener to perform an action      for (int i = 0; i < m_listener.length; i++)      {         if (m_listener[i] != null)         {            m_listener[i].performAction();         }      }   }//void run()}//class ActionUpdater

⌨️ 快捷键说明

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