I am a new to Java, I met a problem. Once I click the Button, it never shows me another form, just disappear. You can see, I set the button ActionListener, but it only run the second line (close the current form).
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
public class login implements ActionListener {
    public login(){
        JFrame frame = new JFrame("Login");
        frame.setLayout(new GridLayout(5,1));
        JLabel label1 = new JLabel("User Name:");
        JPanel panel1 = new JPanel();
        frame.add(new JPanel());
        frame.add(panel1);
        panel1.add(label1);
        JLabel label2 = new JLabel("Password:");
        JPanel panel2 = new JPanel();
        frame.add(panel2);
        panel2.add(label2);
        JPanel panel3 = new JPanel();
        JButton button1 = new JButton("Register");
        //button1.addActionListener(this);
        JButton button2 = new JButton("Login");
        //button2.addActionListener(this);
        JButton button3 = new JButton("Cancel");
        //button3.addActionListener(this);
        panel3.add(button1);
        panel3.add(button2);
        panel3.add(button3);
        frame.add(panel3);
        JTextField JTF = new JTextField(12);
        JPasswordField JPF = new JPasswordField(12);
        panel1.add(JTF);
        panel2.add(JPF);
        frame.setResizable(false);
        frame.setVisible(true);
        frame.setSize(300, 200);
        frame.setLocation(300,200);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        button1.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                  new register();
                frame.dispose();
            }
        });
    }
    public static void main(String[] args){
        new login();
    }
    public void actionPerformed(ActionEvent e ){
    }
}
 
    