JavaFx 2 buttons 2 Listner 1 result -
My small application has 2 buttons, each of which has a addActionListener Does the other stuff but the listener is used? The event handler that I add to the pan later will be used, but why?
Here are some snippets of my code:
public class LoginStarter application extension {public static zero main (string [] args) // // TODO auto generated method Stub launch (args); } @ Override Public Voic Rate (Stage Primary Stage) {Textfield UsernameField = New TextField (); UsernameField.setLayoutX (426); UsernameField.setLayoutY (230); UsernameField.setPromptText ("username"); UsernameField.setMinSize (148, 24); UsernameField.setMaxSize (148, 24); Password field password = new password field (); PasswordField.setLayoutX (426); PasswordField.setLayoutY (260); PasswordField.setMinSize (148, 24); PasswordField.setMaxSize (148, 24); PasswordField.setPromptText ("password"); Panel gp = new pane (); . Add Gp.getChildren () (minimizeBtn ()); . Gp.getChildren () add (xBtn ()); Add gp.getChildren () (usernameField) .; Add gp.getChildren () (passwordField) .; Gp.setId ("pane"); Visual View = New View (GP, 1000, 550); Scene.getStylesheets (). AddAll (this.getClass (). GetResource ("gui.css"). ToExternalForm ()); PrimaryStage.initStyle (StageStyle.UNDECORATED); PrimaryStage.setTitle ("Corp Commander v0.0.1"); PrimaryStage.setScene (view); PrimaryStage.show (); } Public button minimizeBtn () {button minimizeBtn = new button (); MinimizeBtn.setText (""); MinimiseBtn.setMaxSize (20, 20); MinimiseBtn.setMinSize (20, 20); MinimizeBtn.setId ("minimiseBtn"); MinimizeBtn.setLayoutX (956); MinimizeBtn.setLayoutY (2); MinimizeBtn.setOnAction (minimizeBtnListener ()); Return minimum BTN; } Private Event Handler & lt; Action & gt; MinimiseBtnListener () {Event Handler & lt; Action Event & gt; Eh = new event handler & lt; Action Event & gt; () {@ Override Public Wide Handle (ActionAge RGEL) {System.out.println ("at least"); }}; Return eh; } Public button xBtn () {button xBtn = new button (); XBtn.setText (""); XBtn.setMaxSize (20, 20); XBtn.setMinSize (20, 20); XBtn.setId ("xBtn"); XBtn.setLayoutX (978); XBtn.setLayoutY (2); XBtn.setOnAction (xbtnListener ()); Return xBtn; } Private Event Handler & lt; Action & gt; XbtnListener () {Event Handler & lt; Action Event & gt; Eh = new event handler & lt; Action Event & gt; () {@ Override Public Wide Handle (ActionAge RGEL) {System.out.println ("exit"); System.exit (0); }}; Return eh; }} This is used for CSS:
@CHARSET "ISO-885 9-1"; #pine {-fx-background-image: url ("background_image.jpg"); -fx-background-repeat: stretch; -fx-background-size: 1000 550; -fx-background-position: center center; -fx-effect: drop down (three-pass-box, black, 30, 0.5, 0, 0); Opacity: 0.95; } #xBtn {-fx-background-image: url ("exitBtn2.png"); -fx-background-repeat: stretch; -fx-background-size: 20 20; -fx-background-position: center center; -fx-effect: drop down (three-pass-box, black, 30, 0.5, 0, 0); -fx- Background Color: Transparent; } #mini btn {-fx-background-image: url ("minusBtn2.png"); -fx-background-repeat: stretch; -fx-background-size: 20 20; -fx-background-position: center center; -fx-effect: drop down (three-pass-box, black, 30, 0.5, 0, 0); -fx- Background Color: Transparent; }
Comments
Post a Comment