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.

Results 1 to 11 of 11

Thread: Help with GUI Password Tester

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation 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


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,462
    My Mood
    Hungover
    Thanks
    144
    Thanked 639 Times in 547 Posts

    Default 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.

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Help with GUI Password Tester

    Please post your code for us to see..
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  5. #5
    Junior Member
    Join Date
    Dec 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

    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

    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

    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!

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,462
    My Mood
    Hungover
    Thanks
    144
    Thanked 639 Times in 547 Posts

    Default 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?

  7. #7
    Junior Member
    Join Date
    Dec 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with GUI Password Tester

    Yeah, I know, but thats the way my teacher wants it to be done.

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,462
    My Mood
    Hungover
    Thanks
    144
    Thanked 639 Times in 547 Posts

    Default 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?

  9. #9
    Junior Member
    Join Date
    Dec 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with GUI Password Tester

    How would I go about doing that?

  10. #10
    Junior Member
    Join Date
    Dec 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  11. #11
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,462
    My Mood
    Hungover
    Thanks
    144
    Thanked 639 Times in 547 Posts

    Default Re: Help with GUI Password Tester

    Quote Originally Posted by java.kid21 View Post
    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?

Similar Threads

  1. Password Tester GUI HELP
    By java.kid21 in forum Object Oriented Programming
    Replies: 3
    Last Post: December 7th, 2010, 10:35 PM
  2. password.java
    By nickpuma19 in forum Object Oriented Programming
    Replies: 5
    Last Post: November 11th, 2010, 12:29 AM
  3. bandwith tester
    By messithe1 in forum Java SE APIs
    Replies: 0
    Last Post: January 19th, 2010, 09:37 PM
  4. Unable to open web service tester page
    By oneofthelions in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: December 13th, 2009, 05:20 PM
  5. password
    By 5723 in forum Algorithms & Recursion
    Replies: 9
    Last Post: July 9th, 2009, 05:26 AM