Basically, I have to do the same thing that is on this website:tigerRam | COSC 181 Lab 7.1 | Password Tester
I dont need to check my GUI layout and my layout should not be in he constructor. I need to use other classes that extend JPanel.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Basically, I have to do the same thing that is on this website:tigerRam | COSC 181 Lab 7.1 | Password Tester
I dont need to check my GUI layout and my layout should not be in he constructor. I need to use other classes that extend JPanel.
Last edited by java.kid21; December 7th, 2010 at 02:58 PM.
Okay, so here is the code I have.
import java.awt.*; // for layout managers import java.awt.event.*; // for event handling import javax.swing.*; // for GUI components public class PasswordCheck extends JFrame { private LaxPanel laxPanel; private StrictPanel strictPanel; public PasswordCheck() { super("Password Checker"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); JPanel northPanel = new JPanel(); northPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); contentPane.add(northPanel, BorderLayout.NORTH); String instructions = "<html>Welcome to Password Tester.<br>" + "Choose how you want to evaluate your password,<br>" + "enter it below, and click evaluate</html>"; northPanel.add(new JLabel(instructions, JLabel.CENTER), BorderLayout.NORTH); JPanel centerPanel = new JPanel(new GridLayout(0, 3, 10, 10)); centerPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10)); contentPane.add(centerPanel, BorderLayout.CENTER); laxPanel = new LaxPanel(); centerPanel.add(laxPanel); strictPanel = new StrictPanel(); centerPanel.add(strictPanel); JPanel southPanel = new JPanel(); southPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); contentPane.add(southPanel, BorderLayout.SOUTH); JButton evaluate = new JButton("Evaluate"); southPanel.add(evaluate); evaluate.addActionListener(new Listener()); pack(); setVisible(true); } private class Listener implements ActionListener { public void actionPerformed(ActionEvent event) { evaluation(); } } private void evaluation() { String lax = laxPanel.getLax(); String strict = strictPanel.getStrict(); if (lax == null && strict == null) { JOptionPane.showMessageDialog(this, "You need to select either lax or strict evaluation.", "PasswordCheck", JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(this, ("Your password is secure"), "PasswordCheck", JOptionPane.INFORMATION_MESSAGE); } } public static void main(String[] args) { new PasswordCheck(); } }
import javax.swing.*; public class LaxPanel extends JPanel { private JRadioButton laxButton; public LaxPanel() { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); laxButton = new JRadioButton("Lax evaluation"); add(laxButton); } public String getLax() { if (laxButton.isSelected()) return "lax button"; else return null; } }
import javax.swing.*; public class StrictPanel extends JPanel { private JRadioButton strictButton; public StrictPanel() { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); strictButton = new JRadioButton("Strict evaluation"); add(strictButton); } public String getStrict() { if (strictButton.isSelected()) return "Strict button"; else return null; } }
from here I need to make it so only one radio button can be chosen, but since they are on different panels I don't think I can add a button group. I also need to put in a user input box above the evaluate button so the user can input their password. Then I need to evaluate if their password is strong or not based on the criteria above.
Are you asking how to make sure that they don't have lax and strict on at same time?
If so, use ButtonGroup.
ButtonGroup group = new RadioButtonGroup(); JRadioButton lax = new JRadioButton("Lax"); JRadioButton strict = new JRadioButton("Strict"); group.add(lax); group.add(strict);
Now you can select "Lax" or "Strict", but not both.
And selecting "Lax" automatically deselects "Strict" and selecting "Strict" automatically deselects "Lax".
Last edited by javapenguin; December 7th, 2010 at 07:10 PM.
yeah, but they are in two different panels. Is there a way to keep the panels separate like i have them and make it so they are in a buttongroup?