Help with GUI Password Tester
I need to make a password tester. I have some code already, but it has a lot of holes. I need to extend JPanel, so when I click on the JRadioButton in one panel and the one in the other they both get checked. I need it so only one is accepted. I also need to put a user input box in my GUI?
Can anyone help?
massive appreciation
Re: Help with GUI Password Tester
What's your specific question? Break your problem up into separate steps, and ask about them one at a time.
Re: Help with GUI Password Tester
Okay, so here is the deal. I have two panels and each panel has its own radio button. When the panels are added to the GUI, the radiobuttons show and can be clicked. The problem, however, is that since they are in two different .java files because I had to make a new file for each panel then add it to the GUI, both can be clicked. I need to make it so that I can only select one, similar to if they were in a button group. Im not sure if I can use a button group because they are in two different panels. Any solutions?
Re: Help with GUI Password Tester
Please post your code for us to see..
Re: Help with GUI Password Tester
This first code is the main panel. I didn't included the action event stuff because its not completely finished yet.
Code Java:
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;
private TextField input = new TextField(25);
private String userInput;
public PasswordCheck()
{
super("Password Checker");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
JPanel northPanel = new JPanel();
contentPane.add(northPanel, BorderLayout.NORTH);
String instructions = "<html>Welcome to Password Tester. Choose how you want to<br>"
+ " evaluate your password, enter it below, and click evaluate</html>";
northPanel.add(new JLabel(instructions, JLabel.CENTER), BorderLayout.NORTH);
JPanel centerPanel = new JPanel();
contentPane.add(centerPanel, BorderLayout.CENTER);
String info = "";
centerPanel.add(new JLabel(info, JLabel.CENTER),BorderLayout.CENTER);
JPanel westPanel = new JPanel(new GridLayout(0, 1, 10, 10));
laxPanel = new LaxPanel();
westPanel.add(laxPanel, BorderLayout.WEST);
contentPane.add(westPanel, BorderLayout.WEST);
JPanel eastPanel = new JPanel();
strictPanel = new StrictPanel();
eastPanel.add(strictPanel, BorderLayout.EAST);
contentPane.add(eastPanel, BorderLayout.EAST);
JPanel southPanel = new JPanel();
contentPane.add(southPanel, BorderLayout.SOUTH);
JButton evaluate = new JButton("Evaluate");
southPanel.add(input, BorderLayout.SOUTH);
southPanel.add(evaluate, BorderLayout.NORTH);
evaluate.addActionListener(new Listener());
pack();
setVisible(true);
}
This second code is the lax panel that contains the lax button
Code Java:
import javax.swing.*;
public class LaxPanel extends JPanel
{
private JRadioButton laxButton;
public LaxPanel()
{
laxButton = new JRadioButton("Lax evaluation");
add(laxButton);
}
public String getLax()
{
if (laxButton.isSelected())
return "lax button";
else
return null;
}
}
This third code is the strict panel that contains the strict button
Code Java:
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;
}
}
I need to make it so only one is selected at a time and I also need to add action events to the radiobuttons. To add the action event for the radiobuttons should I add it in the lax and strict panel or in the main panel.
Thanks!
Re: Help with GUI Password Tester
Question: Why are the JRadioButtons in separate classes at all? You know you don't have to subclass a JPanel to use it, right?
Re: Help with GUI Password Tester
Yeah, I know, but thats the way my teacher wants it to be done.
Re: Help with GUI Password Tester
In that case, you could have getter functions that return the JRadioButtons in each of the panel classes, then in the main class that sets everything up, just call those getter functions to add them to the ButtonGroup?
Or you could do it the other way around, and pass the ButtonGroup down into the panel classes?
Re: Help with GUI Password Tester
How would I go about doing that?
Re: Help with GUI Password Tester
Hey, I'd really appreciate some help on this soon. It needs to be finished soon and I don't really know what to do. Thanks
Re: Help with GUI Password Tester
Quote:
Originally Posted by
java.kid21
Hey, I'd really appreciate some help on this soon. It needs to be finished soon and I don't really know what to do. Thanks
How To Ask Questions The Smart Way
I told you what to do. What about it didn't you understand? Where are you stuck now?