利用Timer、TimerTask 编写一条调用windows自带的计算器。代码如下:
import javax.swing.* ;
import java.util.* ;
class MyTimerTask extends TimerTask 
{

public void  run()
{
private Timer t = null ;
    public  MyTimerTask(Timer tm )
{
this.t = tm ;
}
  try
           {
           Runtime.getRuntime().exec("calc.exe") ;
           }
           catch(Exception e)
           {
           e.printStackTrace();
      }
      t.cancel();
     
    }
    public static void main(String [] args)
{
 
     Timer tm = new Timer() ;
    tm.schedule(new MyTimerTask(tm) ,3000) ;


    }
    
   }
编译老是通不过,小弟是新手,请大家赐教。!

解决方案 »

  1.   


    import java.util.*;
    import javax.swing.*;
    import java.util.Timer;
    class MyTimerTask extends TimerTask
    {
        private   Timer t = null ;
         public  MyTimerTask(Timer tm )
    { this.t = tm ;
    } public void  run()
    {
      try
               {
               Runtime.getRuntime().exec("calc.exe") ;
               }
               catch(Exception e)
               {
               e.printStackTrace();
          }
          t.cancel();     }
        public static void main(String [] args)
    {      Timer tm = new Timer() ;
        tm.schedule(new MyTimerTask(tm) ,3000) ;
        }    }