public void start(Stage stage) { Button button = new Button("Click me!"); button.setOnAction( new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { System.out.println("Thanks for clicking!"); } }); stage.setScene(new Scene(button)); stage.show(); }
@Override public void start(Stage primaryStage) { try { TabPane page = (TabPane) FXMLLoader.load(Main.class.getResource("simple.fxml")); Scene scene = new Scene(page); primaryStage.setScene(scene); primaryStage.setTitle("Hotels"); primaryStage.show(); textf = (TextField) scene.lookup("#HotelNameTextb"); Button create = (Button) scene.lookup("#CreateButton"); create.setOnAction(this::handleButtonAction); } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } }
@Override public void start(Stage primaryStage) throws Exception { GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setVgap(10); grid.setHgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); Scene sc = new Scene(grid, 500, 500); String css = Main.class.getResource("Login.css").toExternalForm(); // System.out.println(css); sc.getStylesheets().add(css); Text scenetitle = new Text("Welcome"); // scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20)); grid.add(scenetitle, 0, 0, 1, 1); Label userName = new Label("User Name:"); grid.add(userName, 0, 1); TextField userTextField = new TextField("Мудак"); grid.add(userTextField, 1, 1); Label pw = new Label("Password:"******"Sign in"); HBox hbBtn = new HBox(10); hbBtn.setAlignment(Pos.BOTTOM_RIGHT); hbBtn.getChildren().add(btn); grid.add(hbBtn, 1, 4); final Text actiontarget = new Text(); grid.add(actiontarget, 1, 6); btn.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { // actiontarget.setFill(Color.FIREBRICK); actiontarget.setText("Pressed"); } }); // grid.setGridLinesVisible(true); scenetitle.setId("welc"); actiontarget.setId("act"); primaryStage.setScene(sc); primaryStage.setTitle("Hello World"); primaryStage.show(); }
@Override public void start(final Stage primaryStage) { // initialize the stage primaryStage.setTitle("Modal Confirm Example"); final WebView webView = new WebView(); webView.getEngine().load("http://docs.oracle.com/javafx/"); primaryStage.setScene(new Scene(webView)); primaryStage.show(); // initialize the confirmation dialog final Stage util = new Stage(StageStyle.TRANSPARENT); util.initModality(Modality.APPLICATION_MODAL); util.setScene( new Scene( StackPaneBuilder.create() .children( PaneBuilder.create().styleClass("modal-dialog-glass").build(), HBoxBuilder.create() .styleClass("modal-dialog-content") .children( LabelBuilder.create().text("Will you like this page?").build(), ButtonBuilder.create() .text("Yes") .defaultButton(true) .onAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { // take action and close the dialog. System.out.println( "Liked: " + webView.getEngine().getTitle()); primaryStage.getScene().getRoot().setEffect(null); util.close(); } }) .build(), ButtonBuilder.create() .text("No") .cancelButton(true) .onAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { // abort action and close the dialog. System.out.println( "Disliked: " + webView.getEngine().getTitle()); primaryStage.getScene().getRoot().setEffect(null); util.close(); } }) .build()) .build()) .build(), Color.TRANSPARENT)); util.getScene() .getStylesheets() .add(getClass().getResource("/assets/fxml/modal-dialog.css").toExternalForm()); // show the confirmation dialog each time a new page is loaded. webView .getEngine() .getLoadWorker() .stateProperty() .addListener( new ChangeListener<Worker.State>() { @Override public void changed( ObservableValue<? extends Worker.State> observableValue, Worker.State state, Worker.State newState) { if (newState.equals(Worker.State.SUCCEEDED)) { primaryStage.getScene().getRoot().setEffect(new BoxBlur()); util.show(); util.toFront(); } } }); }