Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-15-2008, 04:45 PM   PM User | #1
nogal
New Coder

 
Join Date: Apr 2008
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
nogal is an unknown quantity at this point
uppercase or lowercase

hi, My code is runnig perfect but I am missing a detail, and I have no idea how to. The situation is when you input the password does not matter if it is upper o lowercase it will say "access granted" otherwise will say "access deined"

Thanks


Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JPasswordB extends JApplet implements ActionListener
{

	Container con = getContentPane ();
	JLabel please = new JLabel ("Please Enter Password");
	Font headlineFont = new Font("Helvetica", Font.BOLD, 36);
 	JButton enter = new JButton("Click to Enter");
	JLabel passtyped = new JLabel ("");
	String password = "Rosebud";
	JPasswordField fieldpassword = new JPasswordField(8);

 	public void init()
	{
		please.setFont(headlineFont);
		con.add(please);
		con.add(fieldpassword);
		con.add(enter);
		con.setLayout(new FlowLayout());
		enter.addActionListener(this);
		fieldpassword.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e)
	{
		String name = fieldpassword.getText();
		if 
		( name.equals ( password ) ) 
			{       
			passtyped.setText("Access granted");
			con.add(passtyped);
			}
				else
				{                              
					passtyped.setText("Access Denied");
					con.add(passtyped);
		  			validate();
				}
	}	
}
nogal is offline   Reply With Quote
Old 04-15-2008, 05:24 PM   PM User | #2
brad211987
Regular Coder

 
brad211987's Avatar
 
Join Date: Sep 2005
Location: Ohio
Posts: 631
Thanks: 10
Thanked 50 Times in 50 Posts
brad211987 is an unknown quantity at this point
Not sure I caught the question there. Right now it looks like your code will be case sensitive, if you want to change that, I would suggest looking at the String class in the javadocs.

http://java.sun.com/j2se/1.5.0/docs/...ng/String.html


Everything you need for comparing strings will be right there, including comparing them while ignoring the case.
brad211987 is offline   Reply With Quote
Old 04-15-2008, 07:26 PM   PM User | #3
Aradon
Moderator-san


 
Aradon's Avatar
 
Join Date: Jun 2005
Location: USA
Posts: 734
Thanks: 0
Thanked 20 Times in 19 Posts
Aradon is on a distinguished road
are you saying you WANT that functionality or you don't have that functionality? Or you do have that functionality and you don't want it?

__________________
"To iterate is human, to recurse divine." -L. Peter Deutsch
Aradon is offline   Reply With Quote
Old 04-15-2008, 07:32 PM   PM User | #4
nogal
New Coder

 
Join Date: Apr 2008
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
nogal is an unknown quantity at this point
uppercase or lowercase

My apologies for not being clear enough.

The idea is when you put the right password it does not matter if it is upper or lower case, the program will say "access granted" but if I put the wrong password (either lower or uppercase) it will say "access denied"

Thanks and sorry again.
nogal is offline   Reply With Quote
Old 04-15-2008, 07:57 PM   PM User | #5
Aradon
Moderator-san


 
Aradon's Avatar
 
Join Date: Jun 2005
Location: USA
Posts: 734
Thanks: 0
Thanked 20 Times in 19 Posts
Aradon is on a distinguished road
If you look at the link posted by brad, you'll see a few equals functions for the string class.


One of these functions is called equalsIgnoreCase(String) You can use this function (rather then equals) to do what you are looking for.

My suggestion though is that you visit the link posted by brad, as it is best that you get as familiar with the Java API as soon as possible (especially if you plan on continuing to program in Java.
__________________
"To iterate is human, to recurse divine." -L. Peter Deutsch
Aradon is offline   Reply With Quote
Old 04-15-2008, 11:34 PM   PM User | #6
nogal
New Coder

 
Join Date: Apr 2008
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
nogal is an unknown quantity at this point
I am still working on that but know I have an additional step. It will be to do that with 5 different passwords. Could you help me?

Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JPasswordC extends JApplet implements ActionListener
{

	Container con = getContentPane ();
	JLabel please = new JLabel ("Please Enter Password");
	Font headlineFont = new Font("Helvetica", Font.BOLD, 30);
 	JButton enter = new JButton("Click to Enter");
	JLabel passtyped = new JLabel ("");
	String[] passwords = {"Rosebud","Redrum","Jason","Surrender","Dorothy"};
	JPasswordField fieldpassword = new JPasswordField(12);

 	public void init()
	{
		please.setFont(headlineFont);
		con.add(please);
		con.add(fieldpassword);
		con.add(enter);
		con.setLayout(new FlowLayout());
		enter.addActionListener(this);
		fieldpassword.addActionListener(this);
		
	}

	public void actionPerformed(ActionEvent e)
	{
		String name = fieldpassword.getText();
		if
		( name.equals ( passwords ) ) 
			{       
			passtyped.setText("Access granted");
			con.add(passtyped);
			validate();
			}
				else
				{                              
					passtyped.setText("Access Denied");
					con.add(passtyped);
		  			validate();
				}
	}	
}
nogal is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:41 PM.


Advertisement
Log in to turn off these ads.