So I am new in swing and working on the hangman game. So the way it is supposed to work is that the user is prompt to welcome message which will last a 3seconds, disappears, and then sends the user to the next frame. Everything is working perfectly except that when I run it the first frame is still visible and running in the shadow even though it goes to the next one. I have tried to use the dispose method but it's just closing the frame without going to the next one. Here is my what I have done so far
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.Timer;
public class PA1test extends JFrame{
public static void main(String[] args) {
    // opens the first page
    JFrame gui = new JFrame("Hangman");
    gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    gui.add(new First_PageImage());
    gui.pack();
    gui.setVisible(true);
  // action to open the second page    
    ActionListener taskPerformer = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            //...Perform a task...
            JFrame secpage = new JFrame("Hangman");
            secpage.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
           secpage.add(new SecondPage());
            secpage.pack();
            secpage.setVisible(true);
        }
    };
    // set timer to perform action after 3 seconds
    Timer timer = new Timer(3000 ,taskPerformer);
    timer.setRepeats(false);
    timer.start();     
}
}
 
     
    