import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.StackPane; import javafx.stage.Stage; public class TestClass extends Application { /** * , . main() Java. */ @Override public void start(Stage primaryStage) { // . Button btn = new Button(); // . btn.setText("Say 'Hello World'"); // . btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Hello World!"); } }); // / . StackPane root = new StackPane(); // . root.getChildren().add(btn); // . ( Swing). Scene scene = new Scene(root, 300, 250); //primaryStage - . // . primaryStage.setTitle("Hello World!"); // primaryStage.setScene(scene); primaryStage.show(); } /** * The main() method is ignored in correctly deployed JavaFX application. * main() serves only as fallback in case the application can not be * launched through deployment artifacts, eg, in IDEs with limited FX * support. NetBeans ignores main(). * * @param args the command line arguments */ public static void main(String[] args) { launch(args); } }
package view; import javafx.application.Application; import javafx.stage.Stage; public class EnterScreen extends Application { @Override public void start(Stage primaryStage) throws Exception { } public static void main(String[] args) { launch(args); } }
package view; import javafx.application.Application; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import javafx.scene.image.ImageView; import javafx.stage.Stage; import javafx.stage.StageStyle; public class EnterScreen extends Application { Stage mainStage = null; @Override public void start(Stage primaryStage) throws Exception { mainStage = new Stage(StageStyle.TRANSPARENT); } public static void main(String[] args) { launch(args); } }
package view; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.StackPane; import javafx.stage.Stage; import javafx.stage.StageStyle; public class EnterScreen extends Application { public Stage mainStage = null; @Override public void start(Stage primaryStage) throws Exception { // , mainStage = new Stage(StageStyle.TRANSPARENT); // StackPane root = new StackPane(); //screen - . . ImageView screen = new ImageView("pict/EnterScreen.png"); // root.getChildren().add(screen); // / AnchorPane anPane = new AnchorPane(); // root.getChildren().add(anPane); // TextField login = new TextField("login"); PasswordField password = new PasswordField(); // login.setPrefSize(179, 24); password.setPrefSize(179, 24); // : . // . , AnchorPane.setLeftAnchor(login,519.0); AnchorPane.setLeftAnchor(password, 519.0); // , AnchorPane.setTopAnchor(login, 297.0); AnchorPane.setTopAnchor(password, 347.0); // anPane.getChildren().add(login); anPane.getChildren().add(password); // . : . : . : ( null, ) Scene scene = new Scene(root, 1024, 768, null); mainStage.setScene(scene); mainStage.show(); } public static void main(String[] args) { launch(args); } }
package view; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.StackPane; import javafx.stage.Stage; import javafx.stage.StageStyle; public class EnterScreen extends Application { public Stage mainStage = null; @Override public void start(Stage primaryStage) throws Exception { mainStage = new Stage(StageStyle.TRANSPARENT); StackPane root = new StackPane(); ImageView screen = new ImageView("pict/EnterScreen.png"); root.getChildren().add(screen); AnchorPane anPane = new AnchorPane(); root.getChildren().add(anPane); TextField login = new TextField("login"); PasswordField password = new PasswordField(); login.setPrefSize(179, 24); password.setPrefSize(179, 24); AnchorPane.setLeftAnchor(login,519.0); AnchorPane.setLeftAnchor(password, 519.0); AnchorPane.setTopAnchor(login, 297.0); AnchorPane.setTopAnchor(password, 347.0); anPane.getChildren().add(login); anPane.getChildren().add(password); // ( ) ImageView rightButton = new ImageView("pict/RightButton.png"); // - rightButton.setOnMouseEntered(new EnterScreenEvents.OnMouseEnterRB()); rightButton.setOnMouseExited(new EnterScreenEvents.OnMouseExitRB()); rightButton.setOnMouseClicked(new EnterScreenEvents.OnMouseClickedRB(this)); // - AnchorPane.setLeftAnchor(rightButton, 567.0); AnchorPane.setTopAnchor(rightButton, 420.0); // - anPane.getChildren().add(rightButton); Scene scene = new Scene(root, 1024, 768, null); mainStage.setScene(scene); mainStage.show(); } public static void main(String[] args) { launch(args); } }
package controller; import javafx.event.Event; import javafx.event.EventHandler; import javafx.scene.image.ImageView; import view.EnterScreen; public class EnterScreenEvents { public static class OnMouseEntered implements EventHandler{ @Override public void handle(Event event) { ImageView iv = (ImageView) event.getSource(); iv.setImage(resManager.getRightPressedButtonImage()); } } public static class OnMouseExit implements EventHandler{ @Override public void handle(Event event) { ImageView iv = (ImageView) event.getSource(); iv.setImage(resManager.getRightButtonImage()); } } public static class OnMouseClickedRB implements EventHandler{ private EnterScreen ES = null; public OnMouseClickedRB(EnterScreen ES) { this.ES = ES; } @Override public void handle(Event event) { } } }
package model; import javafx.scene.image.Image; public class resManager { public static Image getEnterScreenBackground(){ return new Image("pict/EnterScreen.png"); } public static Image getRightButtonImage(){ return new Image("pict/RightButton.png"); } public static Image getRightPressedButtonImage(){ return new Image("pict/RightPressedButton.png"); } }
public void close() { Platform.runLater(new closing()); } private class closing implements Runnable { @Override public void run() { mainStage.close(); } }
Source: https://habr.com/ru/post/168073/
All Articles