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

Thread: I cant figure what way to call another class with this given code, any help welcome.

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

    Default I cant figure what way to call another class with this given code, any help welcome.

    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.

    [code+java]
    //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);
    }
    }
    [/code]
    Last edited by RandomGaisha; November 24th, 2012 at 05:02 AM. Reason: other problem


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

    Default Re: I cant figure what way to call another class with this given code, any help welcome.

    I am confused as to what it is you're trying to do and how your code is not succeeding. If you don't get a decent answer soon, please consider,
    • Post more code, and when doing so, please wrap [code=java] [/code] tags around your code to help make it retain its formatting and be readable.
    • Spend some time to type out a paragraph separate from your code that explains exactly what you're trying to do, your current error messages or exceptions or any misbehaviors.

Similar Threads

  1. Call class method from another class
    By NewbieJavaProgrammer in forum Object Oriented Programming
    Replies: 1
    Last Post: November 21st, 2012, 05:56 AM
  2. Call method(s) within the same class
    By mwr76 in forum Object Oriented Programming
    Replies: 8
    Last Post: September 26th, 2011, 12:58 AM
  3. How do I call a class in a main class
    By Leprechaun_hunter in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 26th, 2011, 03:11 AM
  4. How to call int value from another class
    By IDK12 in forum Java Theory & Questions
    Replies: 7
    Last Post: January 14th, 2011, 08:18 PM
  5. problem with data access when a class call another class
    By ea09530 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 4th, 2010, 05:20 PM

Tags for this Thread