本文整理匯總了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();
}
示例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);
}
}
示例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();
}
示例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");
}
}
示例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();
}
示例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();
}
示例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();
}
示例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>
}
示例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();
}
示例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();
}
示例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();
}
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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();
}