用timer类,定时触发某个功能.
不过具体我也没用过,帮你up ------------------------------------------------------
           我们还年轻牛奶会有的奶牛也会有的 
             可天天在 csdn 混这些会有吗 ??

解决方案 »

  1.   

    用timer类,定时触发某个功能.
    不过具体我也没用过,帮你up ------------------------------------------------------
               我们还年轻牛奶会有的奶牛也会有的 
                 可天天在 csdn 混这些会有吗 ??
      

  2.   

    protected void play()
    {
         getTimeSet().setCurrentMjdIndex(getTimeSet().getCurrentMjdIndex() + 1);
         timeSettings.fireCurrentMjdChange();
         timeSettings.Render();
    }try 
    {
        forward = new JButton(new ImageIcon(Utils.findResource("images/VCRForward.gif")));
    }
    catch (java.io.FileNotFoundException e2) 

       e2.printStackTrace(System.err);
       forward = new JButton();
    }
    forward.setName("forward");
    forward.addActionListener( new ActionListener() {
         public void actionPerformed(ActionEvent evt) {
             play();
    }
    });
    autorun = new Jbutton()
    autorun.addActionListener( new ActionListener() {
         public void actionPerformed(ActionEvent evt) {
                timer = new Timer(true);
                TimerTask tt = new TimerTask()
                {
                      public void run()
                      {
                            play();
                      }
                };
                timer.schedule(tt, 0, 3 * 1000);
    }
    });
    这样行不行?
      

  3.   

    protected TimerThread timerThread=null;autorun.addActionListener( new ActionListener() {
         public void actionPerformed(ActionEvent evt) {
                if(timerThread!=null)
                      return;
                timer = new Timer(true);
                TimerTask tt = new TimerTask()
                {
                      public void run()
                      {
                          timerThread = new TimerThread();
                          timerThread.run();
                      }
                };
                timer.schedule(tt, 0, 3 * 1000);
    }
    });
    stopButton = new Button("stop");
    stopButton.addActionListener( new ActionListener() {
         public void actionPerformed(ActionEvent evt) {
                if(timerThread == null)
                      return;
                timerThread.stop();
    }
    });class TimerThread implements Runnable
    {
          Timer timer;
          public TimerThread()
          {
          }
          public void run()
          {
                timer = new Timer(true);
                TimerTask tt = new TimerTask()
                {
                      public void run()
                      {
                            play();
                      }
                };
                timer.schedule(tt, 0, 3 * 1000);
          }
          public void stop()
          {
                timer.cancel();
          }
    }
      

  4.   

    没有刷新视图是指没刷新组件吗?有没有调用repaint()方法,你看看这个吧,我用得好好的呀,:)
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.Timer;
    import java.util.TimerTask;
    import java.util.Date;public class PlayTest
            extends JFrame
    {
          protected TimerThread timerThread = null;      public PlayTest()
          {
                try
                {
                      jbInit();
                }
                catch (Exception e)
                {
                      e.printStackTrace();
                }
          }
          public static void main(String[] args)
          {
                PlayTest playTest = new PlayTest();
                playTest.setSize(600, 500);
                playTest.setVisible(true);
          }
          private void jbInit() throws Exception
          {
                JPanel jPanel = new JPanel();
                jPanel.setLayout(null);            JButton autorun = new JButton("autorun");
                autorun.setBounds(20,30, 80, 25);
                autorun.addActionListener(new ActionListener()
                {
                      public void actionPerformed(ActionEvent evt)
                      {
                            if (timerThread != null)
                                  return;
                            timerThread = new TimerThread();
                            timerThread.run();
                      }
                });
                jPanel.add(autorun);            JButton stopButton = new JButton("stop");
                stopButton.setBounds(20,80, 80, 25);
                stopButton.addActionListener(new ActionListener()
                {
                      public void actionPerformed(ActionEvent evt)
                      {
                            if (timerThread == null)
                                  return;
                            timerThread.stop();
                            timerThread = null;
                      }
                });
                jPanel.add(stopButton);            this.addWindowListener(new java.awt.event.WindowAdapter()
                {
                      public void windowClosing(WindowEvent e)
                      {
                            this_windowClosing(e);
                      }
                });
                JScrollPane jScrollPane1 = new JScrollPane();
                jScrollPane1.getViewport().add(jPanel);
                this.getContentPane().add(jScrollPane1);
          }      private int count = 0;
          protected void play()
          {
                count++;
                System.out.println("playing..." + count);
          }      private void this_windowClosing(WindowEvent e)
          {
                System.exit(0);
          }      class TimerThread implements Runnable
          {
                Timer timer;
                public TimerThread()
                {
                }
                public void run()
                {
                      timer = new Timer(true);
                      TimerTask tt = new TimerTask()
                      {
                            public void run()
                            {
                                  play();
                            }
                      };
                      timer.schedule(tt, 0, 3 * 1000);
                }
                public void stop()
                {
                      timer.cancel();
                }
          }}