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]