Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a javafx Login GUI Application. I am creating security features, therefore I created two classes TimeStamp and ElaspedTime. How do I create a

I have a javafx Login GUI Application. I am creating security features, therefore I created two classes TimeStamp and ElaspedTime. How do I create a constructor to run the classes within the Login Application? Can you run and make sure it works. Thanks

package sdev425hw2; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.stage.Stage; import java.text.SimpleDateFormat; import java.util.Date; import java.lang.*; import java.util.concurrent.TimeUnit; public class SDEV425HW2 extends Application { @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); // 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); // 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() { // Used to output current time class TimeStamp { public void main(String[] args) { // Get current date time Date date = new Date(); SimpleDateFormat timeStamp = new SimpleDateFormat("MM/dd/yy HH:mm:ss"); String specifiedFormat = timeStamp.format(date); System.out.println("Current Date and Time:"+ specifiedFormat); } } class ElapsedTime{ public void main(String []args){ // Code to start the timer long startTime = System.nanoTime(); long endTime = System.nanoTime(); // Code to calculate the elapsed time. long elapsedInNanos = end-start; long elapsedInNaanos = TimeUnit.SECONDS.convert(elapsedInNanos, TimeUnit.NANOSECONDS) } } @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 (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 { final Text actiontarget = new Text(); grid.add(actiontarget, 1, 6); actiontarget.setFill(Color.FIREBRICK); actiontarget.setText("Please try again."); } } }); // Set the size of Scene Scene scene = new Scene(grid, 500, 400); primaryStage.setScene(scene); primaryStage.show(); } /** * @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 Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions

Question

Write effective persuasive messages within organizations.

Answered: 1 week ago