I have some problems with using dispose() method in my GUI project.
I' am making a GUI swing application for some kind of Elections in IntelliJ.
My problem is, by clicking a button(Confirm1, or 2 or 3) I want to open new JFrame which is checking the age of voter and closes the current JFrame where this button is located by calling dispose().
But frame.dispose(); doesn't work.  
I have my JFrame declared in public static main().  
Should I make reference for it in my ActionListener? I have been looking for solution, but I couldn't find any. 
Here is a code:
import javax.swing.*;  //another libraries
public class ElectionGUI {
    private JPanel labelElection;  // another texfields or etc.
    private JButton Confirm1;
    private JButton Confirm3;
    private JButton Confirm2;
    private JPanel Elections;
    public VotesGUI(){
        Votes votes = new Votes("...","...",0);
        listX.addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if(!e.getValueIsAdjusting()){
                    NrX.setText(listX.getSelectedValue().toString());
                }    
            }
        });
        listY.addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if(!e.getValueIsAdjusting()){
                    NrY.setText(listY.getSelectedValue().toString());
                }
            }
        });
        listZ.addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if(!e.getValueIsAdjusting()){
                    NrZ.setText(listZ.getSelectedValue().toString());
                }
            }
        });
        Confirm1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                votes.VotesX();
                votes.countVotes();
                CheckAge age = new CheckAge();
                age.Check();                        /// referention, to my next //Jframe called psvm Check();
            }
        });
        Confirm2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                votes.VotesY();
                votes.countVotes();
                CheckAge age = new CheckAge();
               age.Check();
            }
        });
        Confirm3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                votes.VotesZ();
                votes.countVotes();
                CheckAge age = new CheckAge();
                age.Check();
            }
        });
    }
    public static void main(String[] args) {
       JFrame frame = new JFrame("Elentions");
       frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
       frame.setVisible(true);
        frame.setContentPane(new ElectionGUI().labelElection);
        frame.pack();
    }
}
 
    