Make Register Form in JavaFX

 


Make Register Form in JavaFX:

Make Register Form in JavaFX - YouTube

________________________________________________ How to Make Register Form in JavaFX?


package application; import javafx.application.Application; import javafx.event.EventHandler; import javafx.geometry.HPos; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import javafx.scene.input.KeyEvent; import javafx.scene.input.MouseEvent; import javafx.scene.layout.GridPane; import javafx.scene.paint.Color; import javafx.stage.Stage; public class JavaFXRegForm extends Application{ @Override public void start(Stage pStage) { GridPane pane = new GridPane(); pane.setAlignment(Pos.CENTER); pane.setPadding(new Insets(11, 12, 13, 14)); pane.setVgap(5); pane.setHgap(5); pane.add(new Label("First name: "), 0, 0); pane.add(new TextField(), 1, 0); pane.add(new Label("Last name: "), 0, 1); pane.add(new TextField(), 1, 1); pane.add(new Label("Select your country: "), 0, 2); ComboBox combobox = new ComboBox(); combobox.getItems().addAll( "USA", "UK", "Canada", "France", "China", "other"); combobox.setPromptText("Select"); pane.add(combobox, 1, 2); pane.add(new Label("Select your gender: "), 0, 3); pane.add(new CheckBox("Male"), 1, 3); pane.add(new CheckBox("Female"), 2, 3); pane.add(new Label("Set new password: "), 0, 4); PasswordField passfield = new PasswordField(); pane.add(passfield, 1, 4); CheckBox showPass = new CheckBox("Show password"); pane.add(showPass, 1, 5); Label lbl = new Label(""); pane.add(lbl, 2, 4); passfield.onKeyReleasedProperty().set(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent arg0) { int length = passfield.getText().toString().length(); if(length < 5) { lbl.setText("Weak"); lbl.setTextFill(Color.RED); } else if(length >= 5 && length <= 10) { lbl.setText("Good"); lbl.setTextFill(Color.BLUE); } else if(length > 10) { lbl.setText("Strong"); lbl.setTextFill(Color.GREEN); } } }); TextField passText = new TextField();        pane.add(passText, 1, 4);         passText.setVisible(false); showPass.addEventFilter(MouseEvent.MOUSE_PRESSED, e -> { passText.setText(passfield.getText()); if(showPass.isSelected()) { passfield.setVisible(true); passText.setVisible(false); }else { passfield.setVisible(false); passText.setVisible(true); } }); pane.add(new Label("Re-Password: "), 0, 6); Label lbl1 = new Label(""); pane.add(lbl1, 2, 6); PasswordField passfield1 = new PasswordField(); pane.add(passfield1, 1, 6); CheckBox showPass1 = new CheckBox("Show password"); pane.add(showPass1, 1, 7); passfield1.onKeyReleasedProperty().set(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent arg0) { if(passfield1.getText().equals(passfield.getText())) { lbl1.setText("Well"); lbl1.setTextFill(Color.GREEN); } else { lbl1.setText("Password doesn't match."); lbl1.setTextFill(Color.RED); } } }); TextField passText1 = new TextField();        pane.add(passText1, 1, 6);        passText1.setVisible(false); showPass1.addEventFilter(MouseEvent.MOUSE_PRESSED, e -> { passText1.setText(passfield1.getText()); if(showPass1.isSelected()) { passfield1.setVisible(true); passText1.setVisible(false); }else { passfield1.setVisible(false); passText1.setVisible(true); } }); Button btnAdd = new Button("save"); pane.add(btnAdd, 5, 8); GridPane.setHalignment(btnAdd, HPos.RIGHT); Button btnCancel = new Button("cancel"); pane.add(btnCancel, 6, 8); GridPane.setHalignment(btnCancel, HPos.RIGHT); Scene scene = new Scene(pane, 500, 250); pStage.setTitle("JavaFX Register Form"); pStage.setScene(scene); pStage.show(); } public static void main(String[] args) { Application.launch(args); } }

________________________________________________


Dark Hers

https://darkhers.blogspot.com

YouTube

https://youtube.com/@darkhers

Instagram

https://instagram.com/darkhers

Facebook

https://www.facebook.com/darkhers

TikTok

https://www.tiktok.com/@darkhers

Pinterest

https://www.pinterest.co.uk/darkhers

Twitter

https://twitter.com/Dark_Hers



Comments

Popular Posts