当前位置: 首页>>代码示例>>Java>>正文


Java Task.setOnFailed方法代码示例

本文整理汇总了Java中javafx.concurrent.Task.setOnFailed方法的典型用法代码示例。如果您正苦于以下问题:Java Task.setOnFailed方法的具体用法?Java Task.setOnFailed怎么用?Java Task.setOnFailed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javafx.concurrent.Task的用法示例。


在下文中一共展示了Task.setOnFailed方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runAsyncTask

import javafx.concurrent.Task; //导入方法依赖的package包/类
public static <T> CompletableFuture<T> runAsyncTask(Callable<T> task) {
	Task<T> jfxTask = new Task<T>() {
		@Override
		protected T call() throws Exception {
			return task.call();
		}
	};

	CompletableFuture<T> ret = new CompletableFuture<T>();

	jfxTask.setOnSucceeded(event -> ret.complete(jfxTask.getValue()));
	jfxTask.setOnFailed(event -> ret.completeExceptionally(jfxTask.getException()));
	jfxTask.setOnCancelled(event -> ret.cancel(false));

	threadPool.execute(jfxTask);

	return ret;
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:19,代码来源:Gui.java

示例2: runProgressTask

import javafx.concurrent.Task; //导入方法依赖的package包/类
public void runProgressTask(String labelText, Consumer<DoubleConsumer> task, Runnable onSuccess, Consumer<Throwable> onError) {
	Stage stage = new Stage(StageStyle.UTILITY);
	stage.initOwner(this.scene.getWindow());
	VBox pane = new VBox(GuiConstants.padding);

	stage.setScene(new Scene(pane));
	stage.initModality(Modality.APPLICATION_MODAL);
	stage.setOnCloseRequest(event -> event.consume());
	stage.setResizable(false);
	stage.setTitle("Operation progress");

	pane.setPadding(new Insets(GuiConstants.padding));

	pane.getChildren().add(new Label(labelText));

	ProgressBar progress = new ProgressBar(0);
	progress.setPrefWidth(400);
	pane.getChildren().add(progress);

	stage.show();

	Task<Void> jfxTask = new Task<Void>() {
		@Override
		protected Void call() throws Exception {
			task.accept(cProgress -> Platform.runLater(() -> progress.setProgress(cProgress)));

			return null;
		}
	};

	jfxTask.setOnSucceeded(event -> {
		onSuccess.run();
		stage.hide();
	});

	jfxTask.setOnFailed(event -> {
		onError.accept(jfxTask.getException());
		stage.hide();
	});

	threadPool.execute(jfxTask);
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:43,代码来源:Gui.java

示例3: createTask

import javafx.concurrent.Task; //导入方法依赖的package包/类
private void createTask(Task<?> task, boolean showDialogue) {
	new Thread(task).start();

	if (showDialogue) {
		task.setOnSucceeded(e -> Dialogue.showInfo("Info", "Success!"));
		task.setOnFailed(e -> Dialogue.showWarning("Failed!").showAndWait());
	}

}
 
开发者ID:nshusa,项目名称:rsam-gui,代码行数:10,代码来源:StoreController.java

示例4: patchOrUnpatch

import javafx.concurrent.Task; //导入方法依赖的package包/类
public void patchOrUnpatch() {
	if (working.get()) return;
	Path path = selectedFile.getValue();
	if (path == null || !Files.isRegularFile(path) || !Files.isWritable(path)) {
		error("Patch error", "The specified file was invalid or was not writable.");
		return;
	}

	FileStatus fileStatus = fileStatusProperty.getValue();
	StringProperty messageProperty = progressStatusLabel.textProperty();

	Task<Void> task;
	switch (fileStatus) {
		case VALID_UNPATCHED:
			task = Patcher.patch(path, messageProperty);
			break;
		case VALID_OUTDATED:
			task = Patcher.update(path, messageProperty);
			break;
		case VALID_PATCHED:
			task = Unpatcher.unpatch(path, messageProperty);
			break;
		default:
			return;
	}

	working.set(true);

	task.setOnSucceeded(ignoredArg -> {
		fileStatusBinding.invalidate();
		working.set(false);
		patchButton.requestFocus();
	});
	task.setOnFailed(ignoredArg -> {
		error("Patching failed", "Patching error", messageProperty.get(), task.getException());
	});
}
 
开发者ID:zeobviouslyfakeacc,项目名称:ModLoaderInstaller,代码行数:38,代码来源:MainPanel.java

示例5: refreshAllAppList

import javafx.concurrent.Task; //导入方法依赖的package包/类
@FXML
void refreshAllAppList(ActionEvent event)
{
    try
    {
        Task<Void> syncApp = allAppList.init();
        refreshListButton.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
        refreshListButton.setGraphic(new JFXSpinner());
        syncApp.setOnSucceeded((WorkerStateEvent t) ->
        {
            allAppList.saveToXml();
            setAppNameList();
            listResult.setItems(FXCollections.observableArrayList(currentAppList));
            listResult.refresh();
            refreshListButton.setGraphic(null);
            refreshListButton.setContentDisplay(ContentDisplay.TEXT_ONLY);
        });

        syncApp.setOnFailed(t ->
        {
            JFXSnackbar error = new JFXSnackbar(root);
            error.show(I18n.getMessage("errorrefreshapplist"),3000);
        });
        new Thread(syncApp).start();
    } catch (Exception e)
    {
        e.printStackTrace();
    }
}
 
开发者ID:Matthieu42,项目名称:Steam-trader-tools,代码行数:30,代码来源:AddGameController.java

示例6: start

import javafx.concurrent.Task; //导入方法依赖的package包/类
@Override
public void start(final Stage primaryStage) throws Exception
{
    primaryStage.initStyle(StageStyle.UNDECORATED);
    primaryStage.getIcons().add(new Image("/com/matthieu42/steamtradertools/bundles/images/Icon_STTBluepng.png"));
    Preferences prefs = Preferences.userNodeForPackage(com.matthieu42.steamtradertools.model.Main.class);
    String language = prefs.get(PreferencesKeys.LANGUAGE.toString(),Locale.ENGLISH.getDisplayLanguage());
    Locale locale;
    if(language.equals(Locale.FRENCH.getDisplayLanguage()))
    {
        locale = Locale.FRENCH;
    }
    else
        locale = Locale.ENGLISH;
    I18n.setLocale(locale);
    I18n.setBundle("com/matthieu42/steamtradertools/bundles/lang",locale);
    final AllAppList allAppList = new AllAppList();
    final UserAppList userAppList = new UserAppList();

    File steamAppList = new File("steamAppList.xml");
    if (!steamAppList.exists())
    {
        FXMLLoader splashLoader = new FXMLLoader(getClass().getResource("/com/matthieu42/steamtradertools/view/loadview.fxml"),I18n.getResourceBundle());
        AnchorPane pane = splashLoader.load();
        primaryStage.setScene(new Scene(pane));
        primaryStage.show();
        Task<Void> syncApp = allAppList.init();
        syncApp.setOnSucceeded(t ->
        {
            allAppList.saveToXml();
            continueLaunch(allAppList,userAppList,primaryStage);
        });

        syncApp.setOnFailed(t ->
        {
            return;
        });
        new Thread(syncApp).start();
    } else
    {
        allAppList.loadFromXml();
        continueLaunch(allAppList,userAppList,primaryStage);
    }
}
 
开发者ID:Matthieu42,项目名称:Steam-trader-tools,代码行数:45,代码来源:Main.java

示例7: createBooklets

import javafx.concurrent.Task; //导入方法依赖的package包/类
public void createBooklets(){
	List<File> items = list_files.getItems();
	
	Alert alert = new Alert(AlertType.INFORMATION);
	alert.initStyle(StageStyle.UNDECORATED);
	alert.setHeaderText("Please wait...");
	alert.setContentText("Creating booklets..." );
	alert.getButtonTypes().clear();
	
	BookletSettings settings = new BookletSettings()
			.quality((int) slide_quality.getValue())
			.rotateEvens(check_rotate.isSelected())
			.size(combo_sizes.getValue())
			.dirSetting(getDirSetting())
			.path(getTargetDirectory());
	
	Task<Void> task = new Task<Void>() {
	    @Override public Void call() {
	    	for(File f : items) PrintDF.createBooklet(f, settings);
	    	return null;
	    }
	};

	task.setOnRunning((e) -> alert.show());
	task.setOnSucceeded((e) -> {
		alert.getButtonTypes().add(ButtonType.CANCEL);
		alert.hide();
		alert.getButtonTypes().remove(ButtonType.CANCEL);	
	});
	task.setOnFailed((e) -> {});
	new Thread(task).start();
}
 
开发者ID:Raudius,项目名称:PrintDF,代码行数:33,代码来源:UiController.java

示例8: launchImport

import javafx.concurrent.Task; //导入方法依赖的package包/类
public void launchImport(File file){
    try
    {
        Stage stage = new Stage();
        stage.initStyle(StageStyle.UNDECORATED);
        ResourceBundle bundle = I18n.getResourceBundle();
        ImportFromCSVLoadingController importFromCSVLoadingController = new ImportFromCSVLoadingController();
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/matthieu42/steamtradertools/view/importfromcsvloadingview.fxml"), bundle);
        loader.setController(importFromCSVLoadingController);
        AnchorPane root;
        root = loader.load();
        Scene loading = new Scene(root);
        String css = AppController.class.getResource("/com/matthieu42/steamtradertools/view/style.css").toExternalForm();
        loading.getStylesheets().add(css);
        stage.setScene(loading);
        stage.show();

        Task<Void> importFromCSV = userAppList.importFromCSV(file);

        importFromCSVLoadingController.progressBar.progressProperty().bind(importFromCSV.progressProperty());
        importFromCSV.progressProperty().addListener((obs, oldProgress, newProgress) ->
        {
            double progress = (double) newProgress*100;
            DecimalFormat df = new DecimalFormat("#.##");
            importFromCSVLoadingController.statusLabel.setText(I18n.getMessage("percentageOfGameImported") + " " + df.format(progress) + "%");
        });

        importFromCSV.setOnSucceeded(t ->
        {
            System.out.println("done !");
            JFXSnackbar info = new JFXSnackbar(root);
            info.show(I18n.getMessage("CSVImportSuccess") + "importedData.xml", 3000);
            stage.close();
        });

        importFromCSV.setOnFailed(t ->
        {
            JFXSnackbar error = new JFXSnackbar(root);
            error.show(I18n.getMessage("errorImportingCSV"), 3000);
            return;
        });
        new Thread(importFromCSV).start();


    } catch (IOException e)
    {
        e.printStackTrace();
    }
}
 
开发者ID:Matthieu42,项目名称:Steam-trader-tools,代码行数:50,代码来源:CSVImportTool.java


注:本文中的javafx.concurrent.Task.setOnFailed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。