Javafx changing from one scene to another.
import javafx.application.Application;
import javafx.scene.layout.StackPane;
import javafx.scene.control.Button;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class ChangingScene extends Application
{
public static void main(String[]args)
{
Application.launch(args);
}
@Override
public void start(Stage primaryStage)
{
StackPane root = new StackPane();
Scene next = new Scene(root,600,400);//first scene
Button nextBtn = new Button("next");
root.getChildren().add(nextBtn);//adding nextBtn button on stackpane of scene 2
//creating scene2
StackPane sp = new StackPane();
Scene back = new Scene(sp,600,400);
Button backBtn = new Button("back");
sp.getChildren().add(backBtn);
//adding actions to buttons
nextBtn.setOnAction((ActionEvent t) -> {
primaryStage.setScene(back);//on clicking the button next on scene next it ushers you to scene back
});
backBtn.setOnAction((ActionEvent t) -> {
primaryStage.setScene(next);//on clicking the button back it ushers you back to scene next.
});
primaryStage.setTitle("Changing Scenes");
primaryStage.setScene(next);
primaryStage.show();
}
}
Remarks:
This is what happens for example after a successfully verifying that you credentials match those in the database during a login event you are ushered to another scene or page.
Comments
Post a Comment