So I'm trying to change the panel for my JFrame after 3 seconds from the IntroPanel to the main menu panel. But it doesn't seem to remove the panel and add on the other one when I try to do it. I am not quite sure how I can fix this so I would take any advice to fix this. Thank you!
package gamecs245;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
*
* @author ozhang
*/
public class View extends JFrame {
IntroPanel introP = new IntroPanel();
MainMenuPanel mainP = new MainMenuPanel();
CreditsPanel creditP = new CreditsPanel();
private Timer timer;
private int counter = 3;
private final int delay = 1000;
public View(){
startUp();
add(introP);
ActionListener action = new ActionListener()
{
@Override
public void actionPerformed(ActionEvent event)
{
if(counter == 0)
{
timer.stop();
System.out.println("Panel added");
remove(mainP);
add(mainP);
}
else
{
System.out.println(counter);
counter--;
}
}
};
timer = new Timer(delay, action);
timer.setInitialDelay(0);
timer.start();
}
private void startUp(){
setVisible(true);
setFrameDimensions();
setCloseOperation();
setFrameTitle();
setLocationRelativeTo(null);
}
private void removeIntro(){
remove(introP);
}
private void setFrameDimensions(){
setSize(600,400);
}
private void setCloseOperation(){
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private void actionPerformed(){
}
private void setFrameTitle(){
setTitle("CS245 Project");
}
}