Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class First extends Application {
- public Stage primaryStage2,primaryStage3;
- Second v=new Second();
- @Override
- public void start(Stage primaryStage) {
- Button btn = new Button();
- btn.setText("Press");
- this.primaryStage3=primaryStage;
- btn.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- v.open();
- }
- });
- StackPane root = new StackPane();
- root.getChildren().add(btn);
- Scene scene = new Scene(root, 300, 250);
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
- public class Second {
- Stage primaryStage2;
- First a=new First();
- public void open(){
- primaryStage2=new Stage();
- StackPane root = new StackPane();
- Scene scene = new Scene(root, 300, 250);
- primaryStage2.setScene(scene);
- a.primaryStage3.close();
- primaryStage2.show();
- }
- }
- package application;
- import javafx.application.Application;
- import javafx.stage.Stage;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.layout.BorderPane;
- public class Main extends Application
- {
- BorderPane root = new BorderPane();
- Button btn=new Button("Click Here");
- Stage primaryStage;
- Scene scene ;
- public Main()
- {
- btn.setPrefWidth(75);
- btn.setPrefHeight(15);
- btn.setOnAction((e)->
- {
- SubClass s=new SubClass(primaryStage);
- });
- }
- @Override
- public void start(Stage primaryStage)
- {
- try {
- this.primaryStage=primaryStage;
- // root.getChildren().add(btn);
- scene = initStage();
- scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
- primaryStage.setScene(scene);
- primaryStage.show();
- } catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- private Scene initStage()
- {
- root.setCenter(btn);
- return new Scene(root,150,150);
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
- package application;
- import javafx.scene.Scene;
- import javafx.scene.layout.StackPane;
- import javafx.stage.Stage;
- public class SubClass
- {
- StackPane root = new StackPane();
- Stage stage;
- public SubClass(Stage stage)
- {
- Scene scene=new Scene(root,300,300);
- stage.setScene(scene);
- stage.show();
- }
- }
- package signIn;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Alert;
- import javafx.scene.control.Alert.AlertType;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.StackPane;
- import javafx.scene.layout.VBox;
- import javafx.stage.Stage;
- public class JavaFXWindowDemo extends Application {
- private String loggedInUser;
- public static void main(String[] args) {
- launch(args);
- }
- // How to open a new window in JavaFX
- @Override
- public void start(Stage primaryStage) throws Exception {
- Button btnLogin = new Button();
- btnLogin.setText("Login");
- btnLogin.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- showLoginScreen();
- }
- });
- // A layout container for UI controls
- StackPane root = new StackPane();
- root.getChildren().add(btnLogin);
- // Top level container for all view content
- Scene scene = new Scene(root, 300, 250);
- // primaryStage is the main top level window created by platform
- primaryStage.setTitle("JavaFX Demo");
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- public void setLoggedInUser(String user) {
- loggedInUser = user;
- Alert alert = new Alert(AlertType.INFORMATION);
- alert.setTitle("Successful login");
- alert.setHeaderText("Successful login");
- String s = user + " logged in!";
- alert.setContentText(s);
- alert.show();
- }
- public void showLoginScreen() {
- Stage stage = new Stage();
- VBox box = new VBox();
- box.setPadding(new Insets(10));
- // How to center align content in a layout manager in JavaFX
- box.setAlignment(Pos.CENTER);
- Label label = new Label("Enter username and password");
- TextField textUser = new TextField();
- textUser.setPromptText("enter user name");
- TextField textPass = new TextField();
- textPass.setPromptText("enter password");
- Button btnLogin = new Button();
- btnLogin.setText("Login");
- btnLogin.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- // Assume success always!
- setLoggedInUser(textUser.getText());
- stage.close(); // return to main window
- }
- });
- box.getChildren().add(label);
- box.getChildren().add(textUser);
- box.getChildren().add(textPass);
- box.getChildren().add(btnLogin);
- Scene scene = new Scene(box, 250, 150);
- stage.setScene(scene);
- stage.show();
- }
- }
- public class Second {
- Stage primaryStage2;
- First a=new First();
- public void open(){
- primaryStage2=new Stage();
- StackPane root = new StackPane();
- Scene scene = new Scene(root, 300, 250);
- primaryStage2.setScene(scene);
- a.primaryStage3.close();
- primaryStage2.show();
- }
- }
- btn.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- v.open();
- primaryStage3.close(); // new LINE!!
- }
- });
Add Comment
Please, Sign In to add comment