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: Problem when creating login gui

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Post Problem when creating login gui

    Ok so I am trying to make a login screen, after typing in the password, and pressing the button it should call the given screen, but it gives and error.
    the problem is at the actionListener.

    //This will be the login screen for CardLayoutDemo
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
    public class Login{
    public static void main(String [] args){
    JFrame f1=new JFrame("Keith");
    Container cp=f1.getContentPane();
    cp.setLayout(new FlowLayout());
     
    JLabel l1=new JLabel("Username:");
    JLabel l2=new JLabel("Password:");
    final JTextField tf1=new JTextField(5);
    final JTextField tf2=new JTextField(5);
    JButton login=new JButton("Login");
     
    final String user = "pass";
    final String passwd = "pass";
    cp.add(l1); cp.add(tf1);
    cp.add(l2); cp.add(tf2);
     
     
    ActionListener a1 = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
     
     
    String myText1 = tf1.getText();
    String myText2 = tf2.getText();
     
    if (myText1.equals(user) && (myText2.equals(passwd))
    CardLayoutDemo t1=new CardLayoutDemo();
    }
    };
     
    login.addActionListener(a1);
    cp.add(login);
    f1.pack();
    f1.setDefaultCloseOperation(f1.EXIT_ON_CLOSE);
    f1.setSize(300,300);
    f1.setVisible(true);
    }
    }


  2. #2

    Default Re: Problem when creating login gui

    looks like you are missing an open brace in the if statement.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Problem when creating login gui

    Sorry i don't understand what you mean, where do i put the () exactly?
    thanks in advance.

    --- Update ---

    something like this ?
    but now gives the following errors.

    //
    ActionListener a1 = new ActionListener() {
    	public void actionPerformed(ActionEvent e) {
                   String myText1 = tf1.getText();
    			String myText2 = tf2.getText();
                        if ((myText1.equals(user)) && (myText2.equals(passwd)))
    						CardLayoutDemo t1=new CardLayoutDemo();
                    }
                    };
    //
    it gives the following errors.
                             not a statement
    						CardLayoutDemo t1=new CardLayoutDemo();
    						^
     
                                     ';' expected
    						CardLayoutDemo t1=new CardLayoutDemo();
    						                      ^
    Last edited by curmudgeon; November 24th, 2012 at 09:12 AM. Reason: [code] [/code] tags added

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Problem when creating login gui

    I've added code tags to your posted code above.

    Please post your latest entire Login class code, please take pains to be sure that it is well formatted using 3 to 4 spaces (not tabs) for each level of indentation, that the indentations are uniform, that closing braces are properly lined up, so that we can read and understand your code. Please use [code=java] [/code] tags around your posted code.

Similar Threads

  1. Saving login information into a text file in my GUI App
    By lf2killer in forum Java Theory & Questions
    Replies: 5
    Last Post: November 16th, 2012, 09:14 AM
  2. Problem with LogIn - Multiple users
    By justyStepi in forum AWT / Java Swing
    Replies: 5
    Last Post: April 28th, 2012, 12:18 PM
  3. Buttons and a Login problem
    By raja211991 in forum AWT / Java Swing
    Replies: 1
    Last Post: September 23rd, 2011, 02:41 PM
  4. creating GUI using java, need help?
    By koko20 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 5th, 2011, 02:51 PM
  5. creating a gui
    By rsala004 in forum AWT / Java Swing
    Replies: 2
    Last Post: July 21st, 2009, 02:17 AM

Tags for this Thread