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

Thread: A password code

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default A password code

    I am just trying to get a simple password response!!!
    I have 3 classes working together.
    I am only showing 2 of them. The others just launch classes and make a JFrame.
    Am i over complicating this?
    Here is code of my start_screen class.

    package screen_main;
    import java.awt.event.*;
    import javax.swing.*;
     
     
    public class start_screen{
    	static JButton OK = new JButton("Okay");
    	static JTextField pass_box = new JTextField(15);
    	static JLabel label = new JLabel("Enter the password: ");
     
    	public static void run(){
    		Screen.panel.add(label);
    		Screen.panel.add(pass_box);
    		Screen.panel.add(OK);
    		OK.addActionListener(new ActionListener (){
    			public void actionPerformed(ActionEvent e) {
    				String pass;
    				pass = pass_box.getText();
    				pass_box.setText("");
    				if(pass == "gryff"){
    					System.out.println("Correct");
    				}else{
    					System.out.println("Wrong");
    				}
     
    			}
    		});
    	}
     
     
     
    }
    Last edited by obiedog; October 28th, 2011 at 07:16 PM.


  2. #2
    Junior Member
    Join Date
    Oct 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: A password code

    Also what is the tag to recognize java code?

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: A password code

    Sorry figured it out!!!

  4. #4
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: A password code

    I want to suggest you use a JPasswordField rather than a JTextField. Perfect scenario

  5. #5
    Junior Member
    Join Date
    Oct 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: A password code

    Quote Originally Posted by Tjstretch View Post
    I want to suggest you use a JPasswordField rather than a JTextField. Perfect scenario
    Sorry I forgot to mention that I was using a JPasswordField but it didn't work.

Similar Threads

  1. How to convert password to md5?
    By A4Andy in forum Java Theory & Questions
    Replies: 14
    Last Post: September 13th, 2011, 03:31 AM
  2. Random Password
    By qwerty53 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 19th, 2011, 02:46 AM
  3. password.java
    By nickpuma19 in forum Object Oriented Programming
    Replies: 5
    Last Post: November 11th, 2010, 01:29 AM
  4. [SOLVED] Password screens
    By Dave in forum AWT / Java Swing
    Replies: 7
    Last Post: August 26th, 2009, 06:37 AM
  5. password
    By 5723 in forum Algorithms & Recursion
    Replies: 9
    Last Post: July 9th, 2009, 05:26 AM