Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to turn a boolean into a message?
    text
    copied!<p>Basically the program i made is for a password that limits things to 6-10 characters and requires at least 1 character and 1 password. How do I take the boolean and turn it into a message. I'm using another class for Japplet UI which is why I want to pass this on.</p> <p><strong>Edit:</strong> I dont understand how to do this when my other class gets user input.</p> <pre><code>import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JTextField; 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() { String message = ""; if( Password.check(null) == true) This is what I'm having trouble whit { message = "The Password meets the requirements"; } else { message = "Your password does not match the requirements"; } return message; } } </code></pre>
 

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