Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using this code, when a successful login is created and you click okay when it says you have successfully logged in, I want it to

Using this code, when a successful login is created and you click okay when it says you have successfully logged in, I want it to go to another screen with a vertical list of the options and a data entry space next to type in them. These are as followed; Enter temperature in degress (then a place for the user to type) next line would be Enter wind speed in mph, Then dew point, wind chill andfinally cloud base. Add another class to the project and have main call this screen or window. Thanks!

Account.java

import java.util.regex.Matcher; import java.util.regex.Pattern;

public class Account { private String userName, password; private static final String PASSWORD_PATTERN = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{9})"; public Account() { this.userName = ""; this.password = ""; } public Account(String userName, String password) { Pattern pattern = Pattern.compile(PASSWORD_PATTERN); Matcher matcher = pattern.matcher(password); if(!matcher.matches()) { System.out.println("Invalid pattern for password detected!"); System.exit(-1); } this.userName = userName; this.password = password; }

public String getUserName() { return userName; }

public void setUserName(String userName) { this.userName = userName; }

public String getPassword() { return password; }

public void setPassword(String password) { Pattern pattern = Pattern.compile(PASSWORD_PATTERN); Matcher matcher = pattern.matcher(password); if(!matcher.matches()) { System.out.println("Invalid pattern for password detected!"); System.exit(-1); } this.password = password; } @Override public String toString() { return ("Username: " + this.userName + ", Password: " + this.password); } }

LoginAccountGUI.java (Main class)

import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel;

public class LoginAccountGUI { private static JFrame mainFrame; private static JPanel mainPanel, buttonPanel; private static JButton createButton, loginButton, cancelButton; public static void main(String[] args) { Account account = new Account(); mainFrame = new JFrame("Account Creation and Login"); mainPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); createButton = new JButton("Create Account"); loginButton = new JButton("Login"); cancelButton = new JButton("Cancel"); buttonPanel.add(createButton); buttonPanel.add(loginButton); buttonPanel.add(cancelButton); mainPanel.add(buttonPanel); mainFrame.add(mainPanel); mainFrame.setSize(300, 100); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.setLocationRelativeTo(null); mainFrame.setVisible(true); // action listeners for the buttons createButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { String userName = JOptionPane.showInputDialog(null, "Please enter a username:").trim(); String password = JOptionPane.showInputDialog(null, "Please enter a password " + "Password must at least be 9 characters long and must contain at least: " + " -- one uppercase letter " + " -- one lowercase letter " + " -- one digit").trim(); account.setUserName(userName); account.setPassword(password); JOptionPane.showMessageDialog(null, "Account created successfully!"); }catch(NullPointerException npe){ JOptionPane.showMessageDialog(null, "All fields are mandatory. Please try again!"); System.exit(-1); } } }); loginButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if(account.getUserName().equals("") || account.getPassword().equals("")) { JOptionPane.showMessageDialog(null, "Please create an account to login!"); return; } try { String originalUserName = account.getUserName().trim(); String originalPassword = account.getPassword().trim(); String userNameEntered = JOptionPane.showInputDialog(null, "Please enter the username:").trim(); String passwordEntered = JOptionPane.showInputDialog(null, "Please enter the password:").trim();

if(originalUserName.equals(userNameEntered) && originalPassword.equals(passwordEntered)) JOptionPane.showMessageDialog(null, "Congratulations! You logged in successfully."); else JOptionPane.showMessageDialog(null, "Sorry! Please check your username/password."); }catch(NullPointerException npe){ JOptionPane.showMessageDialog(null, "All fields are mandatory. Please try again!"); System.exit(-1); } } }); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); } }

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

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions