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


Java Task.setOnSucceeded方法代码示例

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


在下文中一共展示了Task.setOnSucceeded方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: updateParentDatabase

import javafx.concurrent.Task; //导入方法依赖的package包/类
/**
 * Update the parent tasks in the database. Used after dragging a task, we
 * only have to update the parents, because the subtasks only depend on
 * their parents, and are independent of the day and the order in the day.
 *
 * @param day
 *         The day of which to update the tasks.
 * @param parentTasks
 *         The list with parents to update.
 */
public void updateParentDatabase(LocalDate day,
                                 List<HomeworkTask> parentTasks) {
    progressIndicator.setVisible(true);
    Task<HomeworkTask> task = new Task<HomeworkTask>() {
        @Override
        public HomeworkTask call() throws Exception {
            updateParentsSynced(day, parentTasks);
            return null;
        }
    };
    task.setOnSucceeded(e -> progressIndicator.setVisible(false));
    exec.execute(task);
}
 
开发者ID:deltadak,项目名称:plep,代码行数:24,代码来源:Controller.java

示例4: updateDatabase

import javafx.concurrent.Task; //导入方法依赖的package包/类
/**
 * Updates database using the given homework tasks for a day.
 *
 * @param day
 *         Date from which the tasks are.
 * @param homeworkTasks
 *         Tasks to be put in the database.
 */
public void updateDatabase(LocalDate day,
                           List<List<HomeworkTask>> homeworkTasks) {
    progressIndicator.setVisible(true);
    Task<List<HomeworkTask>> task = new Task<List<HomeworkTask>>() {
        @Override
        public List<HomeworkTask> call() throws Exception {
            updateDatabaseSynced(day, homeworkTasks);
            return null;
        }
    };
    task.setOnSucceeded(e -> progressIndicator.setVisible(false));
    exec.execute(task);
}
 
开发者ID:deltadak,项目名称:plep,代码行数:22,代码来源:Controller.java

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

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

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

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

示例9: runIndex

import javafx.concurrent.Task; //导入方法依赖的package包/类
public void runIndex(ActionEvent e) {
    Task<Void> task = new Task<Void>() {
        @Override
        protected Void call() throws Exception {
            executeIndex();
            return null;
        }
    };
    task.setOnSucceeded(event -> {
        tabPanel.getSelectionModel().select(0);
        indexLabel.setText("index finished!");
    });
    new Thread(task).start();
}
 
开发者ID:neal1991,项目名称:everywhere,代码行数:15,代码来源:Controller.java

示例10: playTurn

import javafx.concurrent.Task; //导入方法依赖的package包/类
/**
 * Plays the turn for the given player
 *
 * @param scrabble The actual game state
 * @param player   The player that should play his turn
 */
public static void playTurn(Scrabble scrabble, ArtificialIntelligencePlayerInterface player) {
    // First, try to find the possible words
    Task<List<SortedMap<BoardPosition, LetterInterface>>> turnsFindingTask = new Task<List<SortedMap<BoardPosition, LetterInterface>>>() {
        @Override
        protected List<SortedMap<BoardPosition, LetterInterface>> call() throws Exception {
            return PossibleTurnsFinder.findPossibleTurns(scrabble.getLanguage(), scrabble.getBoard(), player);
        }
    };

    turnsFindingTask.setOnSucceeded(event -> {
        List<SortedMap<BoardPosition, LetterInterface>> foundTurns = turnsFindingTask.getValue();

        if (!foundTurns.isEmpty()) {
            try {
                ArtificialIntelligenceHelper.sortTurnsByScore(scrabble.getLanguage().getDictionary(), scrabble.getBoard(), player, foundTurns);
                ArtificialIntelligenceHelper.playTurn(scrabble, player, foundTurns);

                return;
            } catch (InvalidPlayedTurnException ignored) {
            }
        }

        try {
            ArtificialIntelligenceHelper.exchangeLettersWithBag(scrabble, player);
        } catch (NotEnoughLettersException | EmptyBagException e) {
            scrabble.skipTurn();
        }
    });

    new Thread(turnsFindingTask).start();
}
 
开发者ID:Chrisp1tv,项目名称:ScrabbleGame,代码行数:38,代码来源:ArtificialIntelligenceHelper.java

示例11: handleAskHelp

import javafx.concurrent.Task; //导入方法依赖的package包/类
/**
 * Helps the player to play his turn by playing the best turn possible for him
 */
@FXML
protected void handleAskHelp() {
    this.controlButtons.setDisable(true);
    this.playerLettersContainer.setDisable(true);

    HumanPlayerInterface currentPlayer = (HumanPlayerInterface) this.scrabble.getCurrentPlayer();

    Task<SortedMap<BoardPosition, LetterInterface>> bestTurnTaskFinder = ArtificialIntelligenceHelper.getBestTurnPossible(this.scrabble.getLanguage(), this.scrabble.getBoard(), currentPlayer);

    bestTurnTaskFinder.setOnSucceeded(event -> {
        if (null != bestTurnTaskFinder.getValue()) {
            try {
                this.scrabble.playLetters(bestTurnTaskFinder.getValue());
                currentPlayer.decreaseAvailableHelps();

                return;
            } catch (InvalidPlayedTurnException ignored) {
            }
        }

        this.askHelpButton.setDisable(true);
        this.controlButtons.setDisable(false);
        this.playerLettersContainer.setDisable(false);

        this.showAlertOfNoBestTurnPossible();
    });

    new Thread(bestTurnTaskFinder).start();
}
 
开发者ID:Chrisp1tv,项目名称:ScrabbleGame,代码行数:33,代码来源:GameController.java

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

示例13: splashAnimations

import javafx.concurrent.Task; //导入方法依赖的package包/类
public void splashAnimations(){

        Task<Boolean> checkNextScreen = new Task<Boolean>() {
            @Override
            protected Boolean call() throws Exception {
                return skipSplashGuide();
            }
        };


        FadeTransition fadein = new FadeTransition(Duration.seconds(4),gmailLogo);
        fadein.setFromValue(0.3);
        fadein.setToValue(1);
        fadein.setCycleCount(1);
        RotateTransition rotate = new RotateTransition(Duration.seconds(4),gmailLogo);
        rotate.setByAngle(360f);
        rotate.setCycleCount(1);
        ScaleTransition scaleTransition =  new ScaleTransition(Duration.seconds(4), gmailLogo);
        scaleTransition.setToX(4f);
        scaleTransition.setToY(4f);
        scaleTransition.setToZ(4f);
        scaleTransition.setCycleCount(1);
        ParallelTransition pt = new ParallelTransition();
        pt.getChildren().addAll(fadein,rotate,scaleTransition);
        pt.setCycleCount(1);

        Timeline slideDown = new Timeline();
        slideDown.getKeyFrames().add(new KeyFrame(Duration.seconds(1),new KeyValue(topBackground.translateYProperty(),600)));

        Timeline slidingBounce = new Timeline();
        slidingBounce.setCycleCount(2);
        slidingBounce.setAutoReverse(true);
        slidingBounce.getKeyFrames().add(new KeyFrame(Duration.millis(300),new KeyValue(topBackground.translateYProperty(),580)));

        Timeline slideLeft = new Timeline();
        slideLeft.getKeyFrames().add(new KeyFrame(Duration.millis(300), new KeyValue(topBackground.translateXProperty(), -1080)));
        slideLeft.setCycleCount(1);


        SequentialTransition sq = new SequentialTransition();
        sq.getChildren().addAll(new PauseTransition(Duration.seconds(3)), slideDown,
                slidingBounce, new PauseTransition(Duration.millis(300)), pt);
        sq.play();

        checkNextScreen.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
            @Override
            public void handle(WorkerStateEvent event) {
                slideLeft.play();
                if(checkNextScreen.getValue()) {
                    SplashWaitController.startBackgroundTasks();
                    myController.setScreen(AmailMain.splashWaitId);
                    SplashWaitController.installed = true;
                }
                else
                    myController.setScreen(AmailMain.splashGuideId);
            }
        });

        sq.setOnFinished((e) -> {
            Thread t = new Thread(checkNextScreen);
            t.setDaemon(true);
            t.start();
        });

    }
 
开发者ID:ashoknailwal,项目名称:desktop-gmail-client,代码行数:66,代码来源:SplashController.java

示例14: displaySongList

import javafx.concurrent.Task; //导入方法依赖的package包/类
/**
 * Displays the list of songs for a given item.
 * @param item
 */
private void displaySongList(Item item) {
    // hide item list, show loading text
    status.setText("Loading " + item.getIdentifier() + "...");

    ObservableList<Song> songObservableList = FXCollections.observableArrayList();

    // in order to properly update the UI and that the window remains
    // responsive, create a task to perform the (possibly) blocking
    // call to getSongs().
    Task task = new Task<Void>() {
        @Override
        protected Void call() throws Exception {
            List<Song> songs = item.getSongs();

            // add the songs to an observable list
            songObservableList.addAll(songs);
            return null;
        }
    };

    // when the task is finished, add the song list
    // to the UI and set it to be visible.
    task.setOnSucceeded(event -> {
        // set the new list
        songsListView.setItems(songObservableList);
        songsListView.setCellFactory(param -> new SongListViewCell());

        // display song list
        itemsListView.setVisible(false);

        songsListView.getSelectionModel().clearSelection();
        songsListView.setVisible(true);
        otherSources.setVisible(true);
        status.setText("");
        itemsSongsLabel.setText("Songs");
    });

    // start the task
    new Thread(task).start();

}
 
开发者ID:zacwood9,项目名称:attics,代码行数:46,代码来源:UIController.java

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