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


Java SwingWorker.execute方法代碼示例

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


在下文中一共展示了SwingWorker.execute方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: onExportButtonPressed

import javax.swing.SwingWorker; //導入方法依賴的package包/類
@Override
public void onExportButtonPressed() {
    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
            Exporter.writeCurrentClass(silverGhost.getCurrentClassName(),
                    silverGhost.getCurrentClassContent());
            Exporter.writeArchive(silverGhost.getBinaryArchive(),
                    silverGhost.getAllClassNames());
            return null;
        }

        protected void done() {
        }
    };

    worker.execute();
}
 
開發者ID:google,項目名稱:android-classyshark,代碼行數:19,代碼來源:ClassySharkPanel.java

示例8: start

import javax.swing.SwingWorker; //導入方法依賴的package包/類
/**
     * Callback method for demo loader. 
     */
    public void start() {
        if (oscarModel.getRowCount() != 0) return;
        //<snip>Use SwingWorker to asynchronously load the data
        // create SwingWorker which will load the data on a separate thread
        SwingWorker<?, ?> loader = new OscarDataLoader(
                XTableDemo.class.getResource("resources/oscars.xml"), oscarModel);
        
        // display progress bar while data loads
        progressBar = new JProgressBar();
        statusBarLeft.add(progressBar);
        // bind the worker's progress notification to the progressBar
        // and the worker's state notification to this
        BindingGroup group = new BindingGroup();
        group.addBinding(Bindings.createAutoBinding(READ, 
                loader, BeanProperty.create("progress"),
                progressBar, BeanProperty.create("value")));
        group.addBinding(Bindings.createAutoBinding(READ, 
                loader, BeanProperty.create("state"),
                this, BeanProperty.create("loadState")));
        group.bind();
        loader.execute();
//        </snip>
    }
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:27,代碼來源:XTableDemo.java

示例9: requestResume

import javax.swing.SwingWorker; //導入方法依賴的package包/類
private void requestResume() {
	logger.entry();
	SwingWorker<String, Object> worker = new SwingWorker<String, Object>() {

		@Override
		protected String doInBackground() throws Exception {
			if (!requestRunning) {
				requestRunning = true;
				pluginModel.resume();
			}
			return "done";
		}
	};
	setBussyMouse(true);
	worker.execute();
	logger.exit();
}
 
開發者ID:CollapsedDom,項目名稱:Stud.IP-Client,代碼行數:18,代碼來源:PluginView.java

示例10: requestPause

import javax.swing.SwingWorker; //導入方法依賴的package包/類
private void requestPause() {
	logger.entry();
	SwingWorker<String, Object> worker = new SwingWorker<String, Object>() {

		@Override
		protected String doInBackground() throws Exception {
			if (!requestRunning) {
				requestRunning = true;
				pluginModel.pause();
			}
			return "done";
		}
	};
	setBussyMouse(true);
	worker.execute();
	logger.exit();
}
 
開發者ID:CollapsedDom,項目名稱:Stud.IP-Client,代碼行數:18,代碼來源:PluginView.java

示例11: requestAccessToken

import javax.swing.SwingWorker; //導入方法依賴的package包/類
private void requestAccessToken() {
    if (loginModel.isServerSelected()) {
        SwingWorker<String, Object> worker = new SwingWorker<String, Object>() {

            @Override
            protected String doInBackground() throws Exception {
                if (!requestRunning) {
                    requestRunning = true;
                    boolean success = (loginModel.getAccessToken() == ResponseCode.SUCCESS);
                    if (!success) {
                        errorLabel.setText(getLocalized(APP_NOT_AUTHORIZED_IN_STUDIP_LABEL));
                    } else {
                        errorLabel.setText("");
                        model.getPluginModel().activateNewPlugin(loginModel.getPluginInformation(),
                                loginModel.getOAuthConnector());
                    }
                }
                return "done";
            }
        };
        errorLabel.setText("");
        setBussyMouse(true);
        worker.execute();
    }
}
 
開發者ID:CollapsedDom,項目名稱:Stud.IP-Client,代碼行數:26,代碼來源:LoginWindow.java

示例12: actionPerformed

import javax.swing.SwingWorker; //導入方法依賴的package包/類
/**
 * Invoked when an action occurs.
 */
@Override
public void actionPerformed(final ActionEvent e) {
    Sampler c = Sampler.createManualSampler("Self Sampler");  // NOI18N
    if (c != null) {
        if (RUNNING.compareAndSet(null, c)) {
            putValue(Action.NAME, ACTION_NAME_STOP);
            putValue(Action.SHORT_DESCRIPTION, ACTION_NAME_STOP);
            putValue ("iconBase", "org/netbeans/core/ui/sampler/selfSamplerRunning.png"); // NOI18N
            c.start();
        } else if ((c = RUNNING.getAndSet(null)) != null) {
            final Sampler controller = c;

            setEnabled(false);
            SwingWorker worker = new SwingWorker() {

                @Override
                protected Object doInBackground() throws Exception {
                    controller.stop();
                    return null;
                }

                @Override
                protected void done() {
                    putValue(Action.NAME, ACTION_NAME_START);
                    putValue(Action.SHORT_DESCRIPTION, ACTION_NAME_START);
                    putValue ("iconBase", "org/netbeans/core/ui/sampler/selfSampler.png"); // NOI18N
                    SelfSamplerAction.this.setEnabled(true);
                }
            };
            worker.execute();
        }
    } else {
        NotifyDescriptor d = new NotifyDescriptor.Message(NOT_SUPPORTED, NotifyDescriptor.INFORMATION_MESSAGE);
        DialogDisplayer.getDefault().notify(d);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:40,代碼來源:SelfSamplerAction.java

示例13: calculateStatistics

import javax.swing.SwingWorker; //導入方法依賴的package包/類
/**
 * Calculates the statistics of the given {@link ExampleSet} in a {@link SwingWorker}. Once the
 * statistics are calculated, will update the stats on all {@link AttributeStatisticsPanel}s.
 *
 * @param exampleSet
 */
private void calculateStatistics(final ExampleSet exampleSet) {
	final SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

		@Override
		protected Void doInBackground() throws Exception {
			exampleSet.recalculateAllAttributeStatistics();
			waitAtBarrier();

			return null;
		}
	};
	worker.execute();
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:20,代碼來源:MetaDataStatisticsController.java

示例14: checkFirmwareLogic

import javax.swing.SwingWorker; //導入方法依賴的package包/類
/**
 * Check the firmware and logic versions against required ones and display an error if not met.
 */
protected void checkFirmwareLogic(final int requiredFirmwareVersion, final int requiredLogicRevision)
	throws HardwareInterfaceException {
	final StringBuilder updateStringBuilder = new StringBuilder();

	// Verify device firmware version and logic revision.
	final int usbFWVersion = getDID() & 0x00FF;
	if (usbFWVersion < requiredFirmwareVersion) {
		updateStringBuilder
			.append(String.format("Device firmware version too old. You have version %d; but at least version %d is required.\n",
				usbFWVersion, requiredFirmwareVersion));
	}

	final int logicRevision = spiConfigReceive(CypressFX3.FPGA_SYSINFO, (short) 0);
	if (logicRevision < requiredLogicRevision) {
		updateStringBuilder
			.append(String.format("Device logic revision too old. You have revision %d; but at least revision %d is required.\n",
				logicRevision, requiredLogicRevision));
	}

	if (updateStringBuilder.length() > 0) {
		updateStringBuilder
			.append("Please updated by following the Flashy upgrade documentation at 'http://inilabs.com/support/reflashing/'.");

		final String updateString = updateStringBuilder.toString();

		final SwingWorker<Void, Void> strWorker = new SwingWorker<Void, Void>() {
			@Override
			public Void doInBackground() {
				JOptionPane.showMessageDialog(null, updateString);

				return (null);
			}
		};
		strWorker.execute();

		throw new HardwareInterfaceException(updateString);
	}
}
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:42,代碼來源:CypressFX3.java

示例15: startContext

import javax.swing.SwingWorker; //導入方法依賴的package包/類
public void startContext() {
	// TODO Auto-generated method stub

	SwingWorker worker = new SwingWorker() {
		protected Object doInBackground() throws Exception {
			BootstrapManager.getBoostrap(getTomcat().getPort()).deployContexts();
			return null;
		}
	};
	worker.execute();

}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:13,代碼來源:WebApp.java


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