Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 
 
 /*
  * Copyright (C) 2006 Sun Microsystems, Inc. All rights reserved. Use is
  * subject to license terms.
  */ 
 
 package examples;
 
Demonstrates creating a Task that runs periodically. The Tasks's process method runs on the EDT, every period milliseconds.

Author(s):
Hans Muller (Hans.Muller@Sun.COM)
public class PeriodicTaskExample extends SingleFrameApplication {
    JLabel label = null;
    class MyPeriodicTask extends Task<VoidVoid> {
        private final long period;
        MyPeriodicTask(long period) {
            super(PeriodicTaskExample.this);
            this. = period;
        }
        public Void doInBackground() throws InterruptedException {
            while(!isCancelled()) {
                Thread.sleep();
                publish((Void)null);
            }
            return (Void)null;
        }
        public void process(List<Voidignored) {
            long dt = getExecutionDuration(.);
            .setText("Elapsed time: " + dt);
        }
    }
    @Override protected void startup() {
         = new JLabel("Ready...");
        show();
    }
    @Override protected void ready() {
        getContext().getTaskService().execute(new MyPeriodicTask(500L));
    }
    public static void main(String[] args) {
        launch(PeriodicTaskExample.classargs);
    }
New to GrepCode? Check out our FAQ X