请教高手

解决方案 »

  1.   

    // 提供一思路
    class CeiExport 
    {
    private static CeiExport ce = new CeiExport();public static CeiExport getInstance()
    {
    return ce;
    }private CeiExport()
    {
    System.out.println("CeiExport 正在构建中...  构建完毕!");
    }public void printHello()
    {
    System.out.println("你好,朋友");
    }         // 添加此对象的各种操作 .... 
    }public class RemindTask extends TimerTask
    {
    public void run() 
    {
       // CeiExport s=new CeiExport(); 
                         CeiExport s = CeiExport.getInstance(); //返回此对象的最新状态
    }
    public static void main(String[] args)
    {
    Timer timer = new Timer();
            
    timer.schedule(new RemindTask(), 0, 1*2000);
    }
    }
      

  2.   

    import java.util.Timer;
    import java.util.TimerTask;/**
     * Simple demo that uses java.util.Timer to schedule a task to execute
     * once 5 seconds have passed.
     */public class Reminder {
        Timer timer;    public Reminder(int seconds) {
            timer = new Timer();
            timer.schedule(new RemindTask(), seconds*1000);
        }    class RemindTask extends TimerTask {
            public void run() {
                System.out.println("Time's up!");
                timer.cancel(); //Terminate the timer thread
            }
        }    public static void main(String args[]) {
            System.out.println("About to schedule task.");
            new Reminder(5);
            System.out.println("Task scheduled.");
        }
    }或:
    Timer(int delay,
                 ActionListener listener)ActionListener
      

  3.   

    //使用线程
    public class TaskThread extends Thread {
      public void run() {
        try {
          while(true) {
            //执行操作
           sleep(10 * 60 * 1000);
          }
        } catch (Exception e) {
        }
      }
    }public class MainClass {
      public static void main(String[] args) {
        //启动线程
        new TaskThread.start();
      }
    }
      

  4.   

    to mydeman(漫步者)那怎么样让用户按Ctrl键退出呢??
      

  5.   

    You can wirte ower thread class to implement the feature.other one way is using TimerTask class.
      

  6.   

    给你个简单的例子
    private class RemindTask extends TimerTask{
            public void run() {
                ...//要做的写这里.        
            }
        }
    timer = new Timer();
    timer.schedule(new RemindTask(),0, interval*1000*60);//每隔INTERVAL分钟做一次.
      

  7.   

    我也喜欢用三楼的方法,结构比较清晰,或者直接sleep也可以.
      

  8.   

    三楼的调用的地方应该写成:
            TaskThread th = new TaskThread();
            th.start();
      

  9.   

    呵呵,谢谢指出,我也是随便copy一段代码,没有细查
      

  10.   

    to chalsy(白梓健):
       谢谢,不小心写错了,应该是 new TaskThread().start();