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 4 of 4

Thread: Password Tester GUI HELP

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

    Exclamation Password Tester GUI HELP

    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.


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

    Default Re: Password Tester GUI HELP

    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.

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Password Tester GUI HELP

    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.

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

    Default Re: Password Tester GUI HELP

    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?

Similar Threads

  1. password.java
    By nickpuma19 in forum Object Oriented Programming
    Replies: 5
    Last Post: November 11th, 2010, 01:29 AM
  2. Password Program
    By computercoder in forum What's Wrong With My Code?
    Replies: 10
    Last Post: October 20th, 2010, 07:03 AM
  3. bandwith tester
    By messithe1 in forum Java SE APIs
    Replies: 0
    Last Post: January 19th, 2010, 10: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, 06:20 PM
  5. password
    By 5723 in forum Algorithms & Recursion
    Replies: 9
    Last Post: July 9th, 2009, 05:26 AM

Tags for this Thread