/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import javafx.application.Application; import javafx.application.Platform; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.stage.Stage; import javafx.scene.shape.Rectangle; import com.sun.glass.events.MouseEvent; import com.sun.glass.ui.Robot; public class ChangeScene extends Application { public static void main(String[] args) { launch(args); } //@Override public void start(final Stage primaryStage) { Button btn1 = new Button("First Scene"); btn1.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { System.out.println("This is first scene"); } }); Rectangle rec1 = new Rectangle(400,400); rec1.setFill(Color.LIGHTPINK); Group root1 = new Group(); root1.getChildren().addAll(rec1,btn1); Scene s1 = new Scene(root1, 400, 400); primaryStage.setScene(s1); primaryStage.show(); Button btn2 = new Button("Second Scene"); btn2.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { System.out.println("This is second scene"); } }); Group root2 = new Group(); Rectangle rec2 = new Rectangle(400,400); rec2.setFill(Color.LIGHTBLUE); root2.getChildren().addAll(rec2,btn2); final Scene s2 = new Scene(root2, 400, 400); new Thread(new Runnable(){ public void run(){ try { Thread.sleep(5000); } catch (InterruptedException e) { } Platform.runLater (new Runnable(){ public void run(){ primaryStage.setScene(s2); } }); } }).start(); } }