Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a checkbox so the user can choose to show or hide the password #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/com/masterhash/gui/NewLogin.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.masterhash.gui;

import java.util.Random;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
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.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
Expand Down Expand Up @@ -33,20 +38,34 @@ public static void display() {

TextField userNameTextField = new TextField();
userNameTextField.setPromptText("Username");

PasswordField passwordField = new PasswordField();
passwordField.setPromptText("Password");

Button generateButton = new Button("Generate");
TextField shownPasswordField = new TextField();
PasswordField hiddenPasswordField = new PasswordField();

shownPasswordField.setManaged(false);
shownPasswordField.setVisible(false);

CheckBox checkBox = new CheckBox("Hide/Show");
shownPasswordField.managedProperty().bind(checkBox.selectedProperty());
shownPasswordField.visibleProperty().bind(checkBox.selectedProperty());

hiddenPasswordField.managedProperty().bind(checkBox.selectedProperty().not());
hiddenPasswordField.visibleProperty().bind(checkBox.selectedProperty().not());

shownPasswordField.textProperty().bindBidirectional(hiddenPasswordField.textProperty());

HBox generatePasswordArea = new HBox();
generatePasswordArea.getChildren().addAll(passwordField, generateButton);
VBox showOrHideArea = new VBox();
generatePasswordArea.getChildren().addAll(shownPasswordField,hiddenPasswordField, generateButton);
showOrHideArea.getChildren().addAll(generatePasswordArea,checkBox);

Button submitButton = new Button("Submit");

VBox layout = new VBox(10);
layout.setPadding(new Insets(0, 20, 0, 20));
layout.setAlignment(Pos.CENTER_LEFT);
layout.getChildren().addAll(headingLabel, nameTextField, userNameTextField, generatePasswordArea, submitButton);
layout.getChildren().addAll(headingLabel, nameTextField, userNameTextField, showOrHideArea, submitButton);

Scene scene = new Scene(layout, 300, 400);
window.setScene(scene);
Expand Down