Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

in java with wokring 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.

Project Planner

Learning Outcomes Assessed:

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

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); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Prepare and properly label figures and tables for written reports.

Answered: 1 week ago