當前位置: 首頁>>代碼示例>>Java>>正文


Java SwingWorker類代碼示例

本文整理匯總了Java中javax.swing.SwingWorker的典型用法代碼示例。如果您正苦於以下問題:Java SwingWorker類的具體用法?Java SwingWorker怎麽用?Java SwingWorker使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SwingWorker類屬於javax.swing包,在下文中一共展示了SwingWorker類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import javax.swing.SwingWorker; //導入依賴的package包/類
public static boolean run(SwingWorker<?,?> worker, Frame parent) throws Exception {
	ProgressDialog dialog = new ProgressDialog(parent, worker);
	worker.execute();
	dialog.setVisible(true);
	try {
		worker.get();
	}
	catch (ExecutionException e) {
		if (e.getCause() instanceof CancellationException) {
			return false;
		} else if (e.getCause() instanceof Exception) {
			throw (Exception)e.getCause();
		} else {
			// ?!?
			throw new AssertionError(e);
		}
	}
	
	return !worker.isCancelled();
}
 
開發者ID:mgropp,項目名稱:pdfjumbler,代碼行數:21,代碼來源:ProgressDialog.java

示例2: storeColors

import javax.swing.SwingWorker; //導入依賴的package包/類
private static void storeColors() {
    final Properties properties = new Properties();
    final List<ColoredFilter> colors = getRegisteredColors();
    
    new SwingWorker() {
        protected Object doInBackground() throws Exception {
            for (int i = 0; i < colors.size(); i++) try {
                colors.get(i).store(properties, Integer.toString(i) + "_"); // NOI18N
            } catch (Throwable t) {
                Logger.getLogger(PackageColorer.class.getName()).log(Level.INFO, null, t);
            }
            
            try {
                ProfilerStorage.saveGlobalProperties(properties, FILTERS_FILE);
            } catch (IOException e) {
                Logger.getLogger(PackageColorer.class.getName()).log(Level.INFO, null, e);
            }
            
            return null;
        }
    }.execute();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:PackageColorer.java

示例3: authenticate

import javax.swing.SwingWorker; //導入依賴的package包/類
/**
 * authenticates using existing credentials without triggering the auth
 * workflow does nothing if offline
 */
public void authenticate() {
	if (offline)
		return;

	SwingWorker<ConnectionStatus, Object> connectionWorker = AsyncWork.goUnderground(authFunction,
			authContinuation);
	Events.ui.post(RunState.AUTHENTICATION_STARTED);
	try {
		connectionWorker.execute();
		logging.Info("attempting to authenticate");
		String msgAuthFailed = "authentication failed: ";
		try {
			ConnectionStatus result = connectionWorker.get(clientSettings.authTimeout, TimeUnit.SECONDS);
			if (result.status == HttpStatus.SC_OK)
				logging.Info("authentication succeeded");
			else
				logging.Info(msgAuthFailed + result.message.or("unknown reason"));
		} catch (InterruptedException | ExecutionException | TimeoutException e) {
			connectionWorker.cancel(true);
			logging.Info(String.format("%s %s %s", msgAuthFailed, e.getClass().getSimpleName(), e.getMessage()));
		}
	} finally {
		Events.ui.post(RunState.AUTHENTICATION_FINISHED);
	}
}
 
開發者ID:curiosag,項目名稱:ftc,代碼行數:30,代碼來源:ClientController.java

示例4: registerListener

import javax.swing.SwingWorker; //導入依賴的package包/類
private void registerListener() {
  _configMaster.changeManager().addChangeListener(new ChangeListener() {
    @Override
    public void entityChanged(ChangeEvent event) {
      SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
          pullItems();
          runFilter();
          return null;
        }
      };
      worker.execute();
    }
  });
}
 
開發者ID:DevStreet,項目名稱:FinanceAnalytics,代碼行數:17,代碼來源:ViewListModel.java

示例5: createUpgradeWorker

import javax.swing.SwingWorker; //導入依賴的package包/類
/**
 * Creates a new upgrade {@link SwingWorker}.
 * 
 * @return
 */
private static SwingWorker<Void, Void> createUpgradeWorker() {
	return new SwingWorker<Void, Void>() {

		@Override
		protected Void doInBackground() throws Exception {
			RMUrlHandler.handleUrl(URI_LICENSE_UPGRADE);
			return null;
		}

		@Override
		protected void done() {
			try {
				// see if anything failed
				get();
			} catch (ExecutionException | InterruptedException e) {
				LogService.getRoot().log(Level.WARNING,
						"com.rapidminer.license.gui.actions.UpgradeLicenseAction.failed_to_init_upgrade");
			}
		}
	};
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:27,代碼來源:UpgradeLicenseAction.java

示例6: updateTimestampMasterStatus

import javax.swing.SwingWorker; //導入依賴的package包/類
protected void updateTimestampMasterStatus() {
	final SwingWorker<Void, Void> masterUpdateWorker = new SwingWorker<Void, Void>() {
		@Override
		public Void doInBackground() {
			try {
				final int isMasterSPI = spiConfigReceive(CypressFX3.FPGA_SYSINFO, (short) 2);

				isMaster.set(isMasterSPI != 0);
			}
			catch (HardwareInterfaceException e) {
				// Ignore exceptions.
			}

			return (null);
		}
	};

	masterUpdateWorker.execute();
}
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:20,代碼來源:CypressFX3.java

示例7: unregisterListener

import javax.swing.SwingWorker; //導入依賴的package包/類
/**
 * Unsubscribe button action.
 */
private void unregisterListener() {
    new SwingWorker<Boolean, Void>() {
        @Override
        public Boolean doInBackground() {
            return mbeanNotifications.unregisterListener(currentNode);
        }
        @Override
        protected void done() {
            try {
                if (get()) {
                    updateNotifications();
                    validate();
                }
            } catch (Exception e) {
                Throwable t = Utils.getActualException(e);
                if (JConsole.isDebug()) {
                    System.err.println("Problem removing listener");
                    t.printStackTrace();
                }
                showErrorDialog(t.getMessage(),
                        Messages.PROBLEM_REMOVING_LISTENER);
            }
        }
    }.execute();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:29,代碼來源:XSheet.java

示例8: refreshAttributes

import javax.swing.SwingWorker; //導入依賴的package包/類
private void refreshAttributes(final boolean stopCellEditing) {
    SwingWorker<Void,Void> sw = new SwingWorker<Void,Void>() {

       @Override
       protected Void doInBackground() throws Exception {
           SnapshotMBeanServerConnection mbsc =
           mbeansTab.getSnapshotMBeanServerConnection();
           mbsc.flush();
           return null;
       }

       @Override
       protected void done() {
           try {
               get();
               if (stopCellEditing) stopCellEditing();
               loadAttributes(mbean, mbeanInfo);
           } catch (Exception x) {
               if (JConsole.isDebug()) {
                   x.printStackTrace();
               }
           }
       }
    };
    mbeansTab.workerAdd(sw);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:27,代碼來源:XMBeanAttributes.java

示例9: main

import javax.swing.SwingWorker; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    Toolkit.getDefaultToolkit().getSystemEventQueue().push(new EventProcessor());

    SwingWorker<Void, CharSequence> swingWorker =
        new SwingWorker<Void,CharSequence>() {
            @Override
            protected Void doInBackground() {
                publish(new String[] {"hello"});
                publish(new StringBuilder("world"));
                return null;
            }
            @Override
            protected void done() {
                isDone.set(true);
            }
        };
    swingWorker.execute();

    while (! isDone.get()) {
        Thread.sleep(100);
    }
    if (throwable.get() instanceof ArrayStoreException) {
        throw new RuntimeException("Test failed");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:bug6432565.java

示例10: readSettings

import javax.swing.SwingWorker; //導入依賴的package包/類
@Override
public void readSettings(WizardDescriptor wizardDescriptor) {        
    this.wizardDescriptor = wizardDescriptor;
    this.wizardDescriptor.setOptions( new Object[] { WizardDescriptor.FINISH_OPTION } );
    
    importWorker.addPropertyChangeListener( (PropertyChangeEvent evt) -> {
        if ( "state".equals( evt.getPropertyName() ) && evt.getNewValue() == SwingWorker.StateValue.DONE ) {
            if ( importWorker.hasFailed() ) {                    
                onImportFailed( importWorker.getException() );
            } else {
                onImportSuccess( importWorker.isMultiConfigBoard() );
            }
        }
    });
    importWorker.execute();                
}
 
開發者ID:chipKIT32,項目名稱:chipKIT-importer,代碼行數:17,代碼來源:ProgressTrackingStep.java

示例11: aniadirMangas

import javax.swing.SwingWorker; //導入依賴的package包/類
private void aniadirMangas() {
		// // TODO Auto-generated method stub
		final SwingWorker worker = new SwingWorker() {
			@Override
			protected Object doInBackground() throws Exception {
				int inicio = Integer.parseInt(campoInicio.getText());
				int fin = Integer.parseInt(campoFin.getText());
				String url1 = campoUrl1.getText();
				String url2 = campoUrl2.getText();
				for (int i = inicio; i <= fin; i++) {
//					ColaDescarga.addManga(url1 + i + url2);
					textEnlaces.append(url1 + i + url2 + "\n");
				}
				return null;
			}
		};
		worker.execute();
		// dispose();
	}
 
開發者ID:angelh32,項目名稱:JMangaCup,代碼行數:20,代碼來源:Principal.java

示例12: aniadirMangasMasivo

import javax.swing.SwingWorker; //導入依賴的package包/類
private void aniadirMangasMasivo() {
		// TODO Auto-generated method stub
		final SwingWorker worker = new SwingWorker() {
			@Override
			protected Object doInBackground() throws Exception {
				String rawEnlaces = textEnlaces.getText();
				String [] enlaces = rawEnlaces.split("\n");
				for (int i = 0; i < enlaces.length; i++) {
					ColaDescarga.addManga(enlaces[i]);
//					System.out.println("+ "+enlaces[i]);
				}
				return null;
			}
		};
		worker.execute();
		// dispose();
	}
 
開發者ID:angelh32,項目名稱:JMangaCup,代碼行數:18,代碼來源:Principal.java

示例13: aniadirMangas

import javax.swing.SwingWorker; //導入依賴的package包/類
protected void aniadirMangas() {
//		// TODO Auto-generated method stub
		final SwingWorker worker = new SwingWorker(){
			@Override
			protected Object doInBackground() throws Exception {
				int inicio = Integer.parseInt(campoInicio.getText());
				int fin = Integer.parseInt(campoFin.getText());
				String url1=campoUrl1.getText();
				String url2=campoUrl2.getText();
				for (int i = inicio; i <= fin; i++) {
					System.out.println("Aniadiendo: "+url1+i+url2);
					ColaDescarga.addManga(url1+i+url2);
				}
				return null;
			}	
		};
		worker.execute();
		dispose();
	}
 
開發者ID:angelh32,項目名稱:JMangaCup,代碼行數:20,代碼來源:Masivo.java

示例14: createNewSwingWorker

import javax.swing.SwingWorker; //導入依賴的package包/類
/**
 * @return swing worker that starts the search() method and calls done() when that 
 *         task finishes.
 * @see SwingWorker
 */
private SwingWorker<M,U> createNewSwingWorker() {
    return new SwingWorker<M,U>() {
        @Override
        protected M doInBackground() throws Exception {
                return SearchTask.this.search();
        }

        @Override
        protected void done() {
            try {
                M m = get(); // gets computed move
                SearchTask.this.done(m);
                
            } catch (InterruptedException | ExecutionException ex) { 
                System.err.println("Exception in search task: " + ex);
                ex.printStackTrace();
            }
        }            
    };
}
 
開發者ID:AI-12,項目名稱:A-Fucking-AI,代碼行數:26,代碼來源:SearchTask.java

示例15: open

import javax.swing.SwingWorker; //導入依賴的package包/類
public SwingWorker<?, ?> open(File file) {
    if (file == null) {
        JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter(new SupportFileFilter());
        if (mCurrentFile != null && mCurrentFile.getParentFile().exists()) {
            chooser.setCurrentDirectory(mCurrentFile.getParentFile());
        }
        int choice = chooser.showOpenDialog(this);
        if (choice == JFileChooser.APPROVE_OPTION) {
            return new OpenTask(chooser.getSelectedFile());
        } else {
            return null;
        }
    } else {
        return new OpenTask(file);
    }
}
 
開發者ID:MegatronKing,項目名稱:SVG-Android,代碼行數:18,代碼來源:MainFrame.java


注:本文中的javax.swing.SwingWorker類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。