hi, I was wondering how can i make a new frame after the password is entered(if it's correct).
Like if the user enters the correct password than another brower/frame will open.
This is the program:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class password {
private static String password = "pass";
JFrame frame;
JPanel contentPane;
JLabel label;
JButton button;
JTextField name;
public static void main(String[] args) {
JFrame frame = new JFrame("Password");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(100, 100);
JLabel label = new JLabel("Enter password");
JPanel panel = new JPanel();
frame.add(panel);
JPasswordField pass = new JPasswordField(10);
pass.setEchoChar('*');
pass.addActionListener(new AL());
panel.add(label, BorderLayout.WEST);
panel.add(pass, BorderLayout.EAST);
}
static class AL implements ActionListener{
public void actionPerformed(ActionEvent e) {
JPasswordField input = (JPasswordField) e.getSource();
char[] passy = input.getPassword();
String p = new String(passy);
if (p.equals(password)) {
JOptionPane.showMessageDialog(null, "Correct");
password frame = new password();
}
else
JOptionPane.showMessageDialog(null, "Incorrect");
}
}
}