當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。