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

📄 mytask.java

📁 java 完全探索的随书源码
💻 JAVA
字号:
import java.util.Date;import java.util.Timer;import java.util.TimerTask;public class MyTask extends TimerTask{  int maxNumberOfTimesToRun = 0;  // A reference to a date object  Date currentDateTime = null;  static int counter = 1;  Timer myTimer = null;  // Default Constructor  public MyTask( int maxCounter, Timer aTimer )  {    super();    maxNumberOfTimesToRun = maxCounter;    myTimer = aTimer;  }  // Override the abstract method method  public void run()  {    if ( MyTask.counter <= maxNumberOfTimesToRun )    {      System.out.println( MyTask.counter );      // Create a current date instance      currentDateTime = new Date( System.currentTimeMillis() );      // Display the current date object as a string      System.out.println( "MyTask: " + currentDateTime.toString() );      MyTask.counter++;    }    else    {      // Since we reached the counter max, cancel the task      cancel();      // Also cancel the timer since I'm the only one using it.      // This might not be true in all cases      myTimer.cancel();    }  }}

⌨️ 快捷键说明

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