1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
   |  
 
package testjavafxthread;
 
import java.io.IOException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage; 
 
/**
 *
 */
 
public class TestJavaFxThread extends Application {
 
 
    BorderPane root;
 
    @Override
    public void start(Stage primaryStage) {
 
        System.out.println("nom du premmier thread javagx : "+ Thread.currentThread().getName());
        threadJavafx();
 
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {
 
            @Override
            public void handle(ActionEvent event) {              
 
            }
        });
 
 
        //root = new StackPane();
       //root.getChildren().add(btn);
 
       root = new BorderPane();
       root.setCenter(btn);
 
       Scene scene = new Scene(root, 300, 250);
 
        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
 
    public void a()  {
 
        Button b = new Button("iii");
 
        root.setLeft(b);
 
 
 
    } 
 
    /**
     * @param args the command line arguments
     */
 
    public static void main(String[] args) {
        launch(args);
    }
 
    public void threadJavafx() {
          Task longTask = new Task<Void>() {
            @Override
            protected Void call() throws Exception {                             
                System.out.println("nom du nouveau thread : "+ Thread.currentThread().getName());
                a();
                return null;
            }
        };           
       new Thread(longTask).start();     
    }
 
 
 
} | 
Partager