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

📄 antstatus.java

📁 一个TSP问题的图形演示程序
💻 JAVA
字号:
/* *  This code is from the book: * *    Winder, R and Roberts, G (2000) Developing Java *    Software, second edition, John Wiley & Sons. * *  It is copyright (c) 2000 Russel Winder and Graham Roberts. */import SimFrameWork.* ;import javax.swing.* ;/** *  This class displays basic status information for the *  ant simulation. *  By inheriting from Control, the status update is run *  as a separate thread. * *  @version 2.0 March 1999 *  @author Graham Roberts */public class AntStatus extends Control {  /**   *  Use the Grid object to obtain status information and the   *  JLabel to display it.   *   *  @param g grid object providing status information   *  @param l JLabel used to display information on screen   */  public AntStatus(Grid g, JLabel l) {    grid = g ;    label = l ;  }  /**   *  Perform the status update. Use the sleep method to wait 1 second   *  between each update.   */  public void update() {    int count = grid.getTimeCount() ;    label.setText(" Time steps: " +                  new Integer(count).toString() +                  "  (" + (count-lastCount) + " steps per second)") ;    lastCount = count ;    try {      sleep(1000) ;    }    catch (InterruptedException e) { }  }  /**   *  The priority of this thread is increased by one, so   *  that the status thread is guaranteed priority   *  over the simulation thread. This is needed to ensure   *  that the status thread will be run on   *  JVMs that don't support pre-emptive   *  multi-tasking of threads with the   *  same priority.   */  public void run() {    setPriority(getPriority()+1) ;    super.run() ;  }  /**   *  Reference to simulation object holding statistics   */  protected Grid grid ;  /**   *  Label used as status display.   */  JLabel label ;  /**   *  Record of number of time steps completed at last update.   */  private int lastCount = 0 ;} 

⌨️ 快捷键说明

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