Reputation: 2873
After the password is entered i want the window to disappear and pop a new window.
JButton btnEnter = new JButton("Enter");
btnEnter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0)
{
if(passwordField.equals("test"))
{
frame.setVisible(false);
}
else if(!passwordField.equals("test"))
{
JOptionPane.showMessageDialog(null,"Access Denied!!");
}
}
});
btnEnter.setBounds(149, 184, 117, 29);
frame.getContentPane().add(btnEnter);
Upvotes: 0
Views: 80
Reputation: 2494
I'm assuming passwordField is a JTextField, if so, you need to get the text from it, just .getText()
I think and store that in a string. Then test the string. At the moment you are testing if your JTextField equals the string.
Upvotes: 4
Reputation: 117597
Create 2 JFrames and make a reference for each one:
JFrame oldFrame = new JFrame();
// ...
JFrame newFrame = new JFrame();
// ...
// ...
if(passwordField.equals("test"))
{
oldFrame.setVisible(false);
newFrame.setVisible(true);
}
Upvotes: 3