I want to make one simple window with JLabel 'Password', and JPasswordField, and "Login" Button. In the future I want to make a database with Data's, but at the moment I just want to make simple 'move'. If I write in Password Field word which equals my String Field, I want to create new Window and make the old one disappear. My code:
public class Test extends JFrame implements ActionListener {
JButton login,exit;
JTextField tflogin;
JPasswordField pf;
JLabel lpf,ll;
String llogin = "Marco";
String password = "Result";
JFrame nw;
public Test()
{
setBounds(200, 200, 600, 400);;
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(null);
nw = new JFrame("Frame");
nw.setSize(1200,800);
nw.setVisible(false);
pf = new JPasswordField();
pf.setBounds(200, 150, 150, 20);
add(pf);
tflogin = new JTextField();
tflogin.setBounds(200, 120, 150, 20);
add(tflogin);
lpf = new JLabel("Password");
lpf.setBounds(120, 150, 100, 20);
add(lpf);
ll = new JLabel("Login");
ll.setBounds(120, 120, 100, 20);
add(ll);
login = new JButton("Log");
login.setBounds(180, 180, 100, 20);
add(login);
login.addActionListener(this);
exit = new JButton("Exit");
exit.setBounds(290, 180, 100, 20);
add(exit);
exit.addActionListener(this);
}
public static void main(String[] args)
{
Test MyFrame = new Test();
MyFrame.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source == login)
{
if (pf.equals(password));
{
nw.setVisible(true);
}
}
else if (source == exit)
{
dispose();
}
}
}