(Main java file) package P3Q4; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class P3Q4 extends JFrame{     private JLabel jtaMessage=new JLabel();     private JLabel jtaText=new JLabel("Enter your password");     private JPasswordField jpfPassword = new JPasswordField();     private JButton jtnSubmit = new JButton("Submit");     private JLabel jtaEmpty = new JLabel("");      public P3Q4(){           JPanel passwordPanel= new JPanel(new GridLayout(2,2));      JPanel messagePanel= new JPanel(new FlowLayout(FlowLayout.LEFT,0,0));           messagePanel.setBackground(Color.WHITE);      jtaText.setFont(new Font("Arial",Font.BOLD,14));      jtnSubmit.setFont(new Font("Arial",Font.BOLD,14));      jtaMessage.setFont(new Font("Arial",Font.BOLD,14));            jtaMessage.setVerticalAlignment(JLabel.TOP);      jtaMessage.setPreferredSize(new Dimension(430,110));            passwordPanel.add(jtaText);      passwordPanel.add(jpfPassword);      passwordPanel.add(jtaEmpty);      passwordPanel.add(jtnSubmit);                messagePanel.add(jtaMessage);      add(passwordPanel,BorderLayout.CENTER);      add(messagePanel,BorderLayout.SOUTH);            jtnSubmit.addActionListener(new ButtonListener());           setResizable(false);     setTitle("Set Password");     setSize(400, 240);     setLocationRelativeTo(null);     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     setVisible(true); }         private class ButtonListener implements ActionListener {         @Override         public void actionPerformed(ActionEvent e) {                          String inputStr = new String(jpfPassword.getPassword());         try{             Password pw = new Password(inputStr);             jtaMessage.setForeground(Color.BLUE);             jtaMessage.setText("Congratulations! Your password is valid. ");                     }         catch(InvalidPasswordException ex){             jtaMessage.setForeground(Color.RED);             jtaMessage.setText(ex.getMessage());             jpfPassword.grabFocus();             }     } }          public static void main(String[] args) {         new P3Q4();     }      }   (InvalidPasswordException) package P3Q4; public class InvalidPasswordException extends Exception{     public InvalidPasswordException(){         super("Invalid Password Exception");     }          public InvalidPasswordException(String errMsg){         super(errMsg);     } }   (Password) package P3Q4; public class Password {   public Password (String passwordStr) throws InvalidPasswordException {       if (passwordStr== null ||passwordStr.equals("")) {           throw new InvalidPasswordException("Invalid password: password cannot be null or an empty string therefore please key-in the correct password.");       } else {                 int countDigits=0,countLetters=0,total=0;                                  for(int i=0;i

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Based on the java code given how to draw the program user interface design ?

(Main java file)

package P3Q4;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class P3Q4 extends JFrame{

    private JLabel jtaMessage=new JLabel();
    private JLabel jtaText=new JLabel("Enter your password");
    private JPasswordField jpfPassword = new JPasswordField();
    private JButton jtnSubmit = new JButton("Submit");
    private JLabel jtaEmpty = new JLabel("");
    
public P3Q4(){
    
     JPanel passwordPanel= new JPanel(new GridLayout(2,2));
     JPanel messagePanel= new JPanel(new FlowLayout(FlowLayout.LEFT,0,0));
    
     messagePanel.setBackground(Color.WHITE);
     jtaText.setFont(new Font("Arial",Font.BOLD,14));
     jtnSubmit.setFont(new Font("Arial",Font.BOLD,14));
     jtaMessage.setFont(new Font("Arial",Font.BOLD,14));
     
     jtaMessage.setVerticalAlignment(JLabel.TOP);
     jtaMessage.setPreferredSize(new Dimension(430,110));
     
     passwordPanel.add(jtaText);
     passwordPanel.add(jpfPassword);
     passwordPanel.add(jtaEmpty);
     passwordPanel.add(jtnSubmit);
         
     messagePanel.add(jtaMessage);
     add(passwordPanel,BorderLayout.CENTER);
     add(messagePanel,BorderLayout.SOUTH);
     
     jtnSubmit.addActionListener(new ButtonListener());
     
    setResizable(false);
    setTitle("Set Password");
    setSize(400, 240);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
}
        private class ButtonListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
                
        String inputStr = new String(jpfPassword.getPassword());
        try{
            Password pw = new Password(inputStr);
            jtaMessage.setForeground(Color.BLUE);
            jtaMessage.setText("<html>Congratulations! Your password is valid. <html/>");            
        }
        catch(InvalidPasswordException ex){
            jtaMessage.setForeground(Color.RED);
            jtaMessage.setText(ex.getMessage());
            jpfPassword.grabFocus();    
        }
    }
}
    
    public static void main(String[] args) {
        new P3Q4();
    }
    
}

 

(InvalidPasswordException)

package P3Q4;

public class InvalidPasswordException extends Exception{

    public InvalidPasswordException(){
        super("Invalid Password Exception");
    }
    
    public InvalidPasswordException(String errMsg){
        super(errMsg);
    }
}

 

(Password)

package P3Q4;

public class Password {


  public Password (String passwordStr) throws InvalidPasswordException {
      if (passwordStr== null ||passwordStr.equals("")) {
          throw new InvalidPasswordException("<html>Invalid password: password cannot be null or an empty string therefore please key-in the correct password.</html>");
      } else {
                int countDigits=0,countLetters=0,total=0;
                
                for(int i=0;i<passwordStr.length();i++){
                   char ch = passwordStr.charAt(i);
              if (Character.isDigit(ch)){
                countDigits++;
                        }
              else if (Character.isLetter(ch)) 
                     countLetters++; 
                }
                total = countDigits + countDigits ;     
        
          String errMsg = "<html>";
                boolean errorState=false;
          if (countDigits == 0){
          errMsg += "Your password should have at least 1 digit.<br>";
                errorState=true;
                }
                if (countLetters == 0){
          errMsg += "Your password should have at least 1 letter.<br>";
                errorState=true;
                }
                if (total<7){
          errMsg += "Your password should have at least 7 alpha-numeric characters.<br>";
                errorState=true;
                }
          if (errorState==true){
                        errMsg += "<html/>";
              throw new InvalidPasswordException(errMsg);
                }
        }
  } 
}

Set Password
Enter your password
Submit
Invalid password: password cannot be null or an empty string
Set Password
O X
Enter your password
Submit
Your password should have at least 1 letter.
Transcribed Image Text:Set Password Enter your password Submit Invalid password: password cannot be null or an empty string Set Password O X Enter your password Submit Your password should have at least 1 letter.
Set Password
Enter your password
Submit
Your password should have at least 1 digit.
Your password should have at least 7 alpha-numeric
characters.
Set Password
Enter your password
Submit
Congratulations! Your password is valid.
Transcribed Image Text:Set Password Enter your password Submit Your password should have at least 1 digit. Your password should have at least 7 alpha-numeric characters. Set Password Enter your password Submit Congratulations! Your password is valid.
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY