saim2025
saim2025

Reputation: 320

Using swing Timer to switch between JFrames

I have two JFrames A and B. I have a gif running on frame A. After a certain time i want to to close frame A and display frame B. I am using following code but it fires action as soon as program is executed. How can i resolve this issue?

    ActionListener taskPerformer = new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
        new FrameB().setVisible(true);
    }
};
Timer timer = new Timer(100 ,taskPerformer);
timer.setRepeats(false);
timer.start();

Upvotes: 0

Views: 177

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285405

You've written the Timer to activate 100 milliseconds after you call start, which is almost a blink of an eye. So it's only doing what you are telling it to do. If you want to make the delay longer, then code it to be longer. You also can explicitly set the initial delay via setInitialDelay(...) but that's not going to change anything here.

Before you go too much further with this project though, please read The Use of Multiple JFrames: Good or Bad Practice?.

Upvotes: 5

Related Questions