Question: in java with working code Using your Login and User class and JavaFX input form. When the register button is pressed, the extra fields to

in java with working code

Using your Login and User class and JavaFX input form.

When the register button is pressed, the extra fields to register are shown (however you feel best), once the user has filled in the information and presses Register, then the User class instance is created and written to a BINARY file as a serialized object.

When a user attempts to login, you need to read the binary file to see if the user is registered, if they are not registered, then you need to throw an error and register them. Otherwise, you need to redirect them to a "Welcome " screen.

The primary stage should have the title "LOGIN: " and your name.

package com.example.topic5lab5;

import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.PasswordField; import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.layout.VBox; import javafx.stage.Stage;

class Login { String userName; String password;

public Login(String userName, String password) { this.userName = userName; this.password = password; }

@Override public String toString() { return "Username: " + userName + ", Password: " + password; } }

class User { String firstName; String lastName; String email; String phoneNumber; Login login;

public User(String firstName, String lastName, String email, String phoneNumber, Login login) { this.firstName = firstName; this.lastName = lastName; this.email = email; this.phoneNumber = phoneNumber; this.login = login; }

@Override public String toString() { return "First Name: " + firstName + ", Last Name: " + lastName + ", Email: " + email + ", Phone Number: " + phoneNumber + ", Login: {" + login.toString() + "}"; } }

public class Topic5Lab5 extends Application { @Override public void start(Stage primaryStage) { VBox vbox = new VBox(10); vbox.setPadding(new Insets(20));

TextField usernameField = new TextField(); usernameField.setPromptText("Username"); PasswordField passwordField = new PasswordField(); passwordField.setPromptText("Password"); Button loginButton = new Button("Login"); TextArea outputArea = new TextArea();

loginButton.setOnAction(e -> { Login login = new Login(usernameField.getText(), passwordField.getText()); outputArea.setText(login.toString()); usernameField.clear(); passwordField.clear(); });

TextField firstNameField = new TextField(); firstNameField.setPromptText("First Name"); TextField lastNameField = new TextField(); lastNameField.setPromptText("Last Name"); TextField emailField = new TextField(); emailField.setPromptText("Email"); TextField phoneNumberField = new TextField(); phoneNumberField.setPromptText("Phone Number"); Button registerButton = new Button("Register");

registerButton.setOnAction(e -> { Login login = new Login(usernameField.getText(), passwordField.getText()); User user = new User(firstNameField.getText(), lastNameField.getText(), emailField.getText(), phoneNumberField.getText(), login); outputArea.setText(user.toString()); usernameField.clear(); passwordField.clear(); firstNameField.clear(); lastNameField.clear(); emailField.clear(); phoneNumberField.clear(); });

vbox.getChildren().addAll(usernameField, passwordField, loginButton, firstNameField, lastNameField, emailField, phoneNumberField, registerButton, outputArea);

Scene scene = new Scene(vbox, 500, 500);

primaryStage.setTitle("USER: "); primaryStage.setScene(scene); primaryStage.show(); }

public static void main(String[] args) { launch(args); } }

Learning Outcomes Assessed:

  • JavaFX layouts
  • JavaFX Actions
  • Using JavaFX widgets
  • Multiple stages
  • Class design
  • Binary File I/O

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!