public MonitoredTask(SwingWorker task, String msg, Component parentComponent) {
   this.task = task;
   // create the progress monitor
   progressMonitor = new ModalProgressMonitor(parentComponent, msg, "", 0, 100);
   progressMonitor.setProgress(0);
   // add ProgressMonitorExample as a listener on CopyFiles;
   // of specific interest is the bound property progress
   task.addPropertyChangeListener(this);
 }
 // executes in event dispatch thread
 public void propertyChange(PropertyChangeEvent event) {
   // if the operation is finished or has been canceled by
   // the user, take appropriate action
   if (progressMonitor.isCanceled()) {
     task.cancel(true);
   } else if (event.getPropertyName().equals("progress")) {
     // get the % complete from the progress event
     // and set it on the progress monitor
     int progress = ((Integer) event.getNewValue()).intValue();
     progressMonitor.setProgress(progress);
     if (progress >= 100) {
       progressMonitor.close();
     }
   }
 }