Jump to content

How to go to another jframe from one jframe after a certain amount of time?

i need to write a program in java and i want to go to another jframe from my current frame after 10 seconds.How can i do this?

Link to comment
Share on other sites

Link to post
Share on other sites

25 minutes ago, Shammikit said:

i need to write a program in java and i want to go to another jframe from my current frame after 10 seconds.How can i do this?

TimeUnit.SECONDS.sleep(10)

 

then delete the old frame and create the new one

Main Rig: R9 5950X @ PBO, RTX 3090, 64 GB DDR4 3666, InWin 101, Full Hardline Watercooling

Server: R7 1700X @ 4.0 GHz, GTX 1080 Ti, 32GB DDR4 3000, Cooler Master NR200P, Full Soft Watercooling

LAN Rig: R5 3600X @ PBO, RTX 2070, 32 GB DDR4 3200, Dan Case A4-SFV V4, 120mm AIO for the CPU

HTPC: i7-7700K @ 4.6 GHz, GTX 1050 Ti, 16 GB DDR4 3200, AliExpress K39, IS-47K Cooler

Router: R3 2200G @ stock, 4GB DDR4 2400, what are cases, stock cooler
 

I don't have a problem...

Link to comment
Share on other sites

Link to post
Share on other sites

16 hours ago, tarfeef101 said:

TimeUnit.SECONDS.sleep(10)

 

then delete the old frame and create the new one

Instead of sleeping on the AWT thread and causing the entire GUI to freeze, it's much better to make use of javax.swing.Timer:


int delay = 10000; // Delay in milliseconds

Timer timer = new Timer(delay, new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        frameB.setVisible(true); // Show the second frame
        frameA.setVisible(false); // Hide the first frame
    }
});
timer.start();

This will dispatch the event after the specified delay on the swing event dispatching thread.

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, Mooshe said:

Instead of sleeping on the AWT thread and causing the entire GUI to freeze, it's much better to make use of javax.swing.Timer:



int delay = 10000; // Delay in milliseconds

Timer timer = new Timer(delay, new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        frameB.setVisible(true); // Show the second frame
        frameA.setVisible(false); // Hide the first frame
    }
});
timer.start();

This will dispatch the event after the specified delay on the swing event dispatching thread.

True. Been about 5-6 years since I used java, so I am what you might call a bit rusty on my knowledge there. 

Main Rig: R9 5950X @ PBO, RTX 3090, 64 GB DDR4 3666, InWin 101, Full Hardline Watercooling

Server: R7 1700X @ 4.0 GHz, GTX 1080 Ti, 32GB DDR4 3000, Cooler Master NR200P, Full Soft Watercooling

LAN Rig: R5 3600X @ PBO, RTX 2070, 32 GB DDR4 3200, Dan Case A4-SFV V4, 120mm AIO for the CPU

HTPC: i7-7700K @ 4.6 GHz, GTX 1050 Ti, 16 GB DDR4 3200, AliExpress K39, IS-47K Cooler

Router: R3 2200G @ stock, 4GB DDR4 2400, what are cases, stock cooler
 

I don't have a problem...

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×