Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create audit records in Javafx using AU-3 - CONTENT OF AUDIT RECORDS. I can not figure out how to implement logging files into my application.

Create audit records in Javafx using AU-3 - CONTENT OF AUDIT RECORDS. I can not figure out how to implement logging files into my application. Please provide a clear answer or explanation.

public class LogInLogger extends Application {

//counter for login attempts int loginAttempts = 0; //maximum number of login attempts final int numAttempts = 2;

@Override public void start(Stage primaryStage) { primaryStage.setTitle("SDEV425 Login"); // Grid Pane divides your window into grids GridPane grid = new GridPane(); // Align to Center // Note Position is geometric object for alignment grid.setAlignment(Pos.CENTER); // Set gap between the components // Larger numbers mean bigger spaces grid.setHgap(10); grid.setVgap(10);

//Creates alert pop up window Alert alert = new Alert(AlertType.CONFIRMATION); //Creates title alert.setTitle("Warning"); //Creates header alert.setHeaderText("Warning"); //Creates warning text to be displayed alert.setContentText("WARNING. This system is for authorized users only. " + "All usage is subjective to monitoring, recording and auditing. " + "Unauthorized use of the information system is prohibited and subject " + "to ciminal and civiil penalties.");

//Create OK and Cancel buttons with actions Optional warning = alert.showAndWait(); if (warning.get() == ButtonType.OK) { // Create some text to place in the scene Text scenetitle = new Text("Welcome. Login to continue."); // Add text to grid 0,0 span 2 columns, 1 row grid.add(scenetitle, 0, 0, 2, 1); try { // Create Label Label userName = new Label("User Name:"); // Add label to grid 0,1 grid.add(userName, 0, 1);

// Create Textfield TextField userTextField = new TextField(); // Add textfield to grid 1,1 grid.add(userTextField, 1, 1); // Create Label Label pw = new Label("Password:"); // Add label to grid 0,2 grid.add(pw, 0, 2);

// Create Passwordfield PasswordField pwBox = new PasswordField(); // Add Password field to grid 1,2 grid.add(pwBox, 1, 2);

// Create Login Button Button btn = new Button("Login"); // Add button to grid 1,4 grid.add(btn, 1, 4);

final Text actiontarget = new Text(); grid.add(actiontarget, 1, 6);

// Set the Action when button is clicked btn.setOnAction(new EventHandler() {

@Override

public void handle(ActionEvent e) { // Authenticate the user boolean isValid = authenticate(userTextField.getText(), pwBox.getText()); // If valid clear the grid and Welcome the user

//if statement to instruct what action to take when the numAttempts //equal the maximum number of loginAttempts if (loginAttempts == numAttempts) { grid.setVisible(false); GridPane grid3 = new GridPane(); // Align to Center // Note Position is geometric object for alignment grid3.setAlignment(Pos.CENTER); // Set gap between the components // Larger numbers mean bigger spaces grid3.setHgap(10); grid3.setVgap(10); Text exitTitle = new Text("Account locked after 3 failed login attempts"); // Add text to grid 0,0 span 2 columns, 1 row grid3.add(exitTitle, 0, 0, 2, 1); Scene scene2 = new Scene(grid3, 500, 400); primaryStage.setScene(scene2); primaryStage.show();

} else if (isValid) { grid.setVisible(false); GridPane grid2 = new GridPane(); // Align to Center // Note Position is geometric object for alignment grid2.setAlignment(Pos.CENTER); // Set gap between the components // Larger numbers mean bigger spaces grid2.setHgap(10); grid2.setVgap(10); Text scenetitle = new Text("Welcome " + userTextField.getText() + "!"); // Add text to grid 0,0 span 2 columns, 1 row grid2.add(scenetitle, 0, 0, 2, 1); Scene scene = new Scene(grid2, 500, 400); primaryStage.setScene(scene); primaryStage.show(); // If Invalid Ask user to try again } else { //loginAttempts counter loginAttempts++; final Text actiontarget = new Text(); grid.add(actiontarget, 1, 6); actiontarget.setFill(Color.FIREBRICK); actiontarget.setText("Please try again."); } } }); } catch (Exception ex) { ex.printStackTrace(); } // Set the size of Scene Scene scene = new Scene(grid, 500, 400); primaryStage.setScene(scene); primaryStage.show();

} else { //Exit application is Cancel button is selected System.exit(0); } } /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); }

/** * @param user the username entered * @param pword the password entered * @return isValid true for authenticated */ public boolean authenticate(String user, String pword) { boolean isValid = false; if (user.equalsIgnoreCase("sdevadmin") && pword.equals("425!pass")) { isValid = true; } return isValid; } }

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

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions