Note that there are some explanatory texts on larger screens.

plurals
  1. POTurning boolean into a message?
    primarykey
    data
    text
    <p>This program takes a users password and tell them if they have a valid password. The password needs 6-10 characters, which contain at least 1 number and letter. I get user input in my PasswordUI class. My Password class uses that to check if the password is valid and returns a boolean. How do I take that boolean and use it to form a message that I will use in my PasswordUI class?</p> <pre><code>public class PasswordUI extends JApplet implements ActionListener { JLabel passwordLabel = new JLabel(""); JTextField inputBox = new JTextField(40); JButton goButton = new JButton("Go"); Container con = getContentPane(); public void init() { con.setLayout(new FlowLayout()); con.add(new JLabel("Enter a password between 6-10 characters. Must contain atleast 1 number and 1 letter")); con.add(inputBox); con.add(goButton); con.add(passwordLabel); goButton.addActionListener(this); inputBox.addActionListener(this); } public void actionPerformed(ActionEvent e) { String userInput = inputBox.getText(); boolean pass= Password.check(userInput); //String message = Password.display(null); Password mess= new Password(); passwordLabel.setText( mess.getDisplay()); } } public class Password { public static boolean check(String str) { boolean result = false; char ch; int letterCount = 0, digitCount= 0 ; int length = str.length(); if(str.length()&gt;= 6) { if(str.length()&lt;= 10) { for (int i=0; i&lt;length; i++ ) //i&lt;end { ch = str.charAt(i); if (Character.isDigit(ch)) digitCount++; else if (Character.isLetter(ch)) letterCount++; } if (letterCount &gt;= 1 &amp;&amp; digitCount &gt;= 1) result = true; } } return result; } public String getDisplay()//how do I do this? { String message = result ? "Your password is valid" : "You Password is invalid"; //result isn't working return message; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload