im a newbie on this, ive been watching videos to practice in Java GUI's, what im trying to do is execute a login gui and when it successfully enters the username and password, it goes to another window.
public class login implements ActionListener{
private static JLabel label;
private static JTextField userText;
private static JLabel passwordLabel;
private static JPasswordField passwordText;
private static JButton button;
private static JLabel test;
public static void main(String[] args) {
JPanel panel = new JPanel();
JFrame frame = new JFrame();
frame.setSize(350,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon image = new ImageIcon("PICTURE.png");
frame.setIconImage(image.getImage());
frame.setTitle("Login : TITLEHERE");
frame.setResizable(false);
frame.add(panel);
panel.setLayout(null);
label = new JLabel("User");
label.setBounds(10, 20, 80, 25);
panel.add(label);
userText = new JTextField(20);
userText.setBounds(100,20,165,25);
panel.add(userText);
passwordLabel = new JLabel ("Password");
passwordLabel.setBounds(10,50,80,25);
panel.add(passwordLabel);
passwordText = new JPasswordField();
passwordText.setBounds(100, 50, 165, 25);
panel.add(passwordText);
button = new JButton("Login");
button.setBounds(10, 80, 80 , 25);
button.addActionListener(new login());
panel.add(button);
test = new JLabel("");
test.setBounds(10,110,300,25);
panel.add(test);
frame.setVisible(true);}
the problem i have is when i try to access the frame from the main, it says "Frame cannot be resolved." It works on other videos but it doesnt work for mine. heres my actionPerformed code:
@Override
public void actionPerformed(ActionEvent e) {
String user = userText.getText();
String password = passwordText.getText();
System.out.println(user + ", " +password);
if(user.equals("NAME") && password.equals("LASTNAME")) {
test.setText("Login successful!");//no spaces and all capital for success
myFrame home = new myFrame();
frame.setVisible(false);// this,
frame.discard();// - and this does not work.
}
else {
test.setText("Login Failed");
}
}