当前位置: 首页>>代码示例>>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;未经允许,请勿转载。