简体   繁体   English

如何在特定时间后从 JFrame 类跳转

[英]How to jump from a JFrame class after a specific time

I would like to go to jump from my progress bar (which is not an entirely progress just a gif) to another JFrame that would take me to the Login Frame after 5seconds but i don't want to use splash nor use buttons.我想从我的进度条(这不是一个完全的进度只是一个 gif)跳转到另一个JFrame ,它会在 5 秒后将我带到登录框架,但我不想使用启动画面或使用按钮。

My Loading Frame source code :我的Loading框架源代码:

public static void main(String[] args) {
    JFrame frame = new JFrame("Loading");
    frame.getContentPane().setBackground(Color.white);
    ImageIcon loading = new ImageIcon("loading.gif");
    frame.add(new JLabel("", loading, JLabel.CENTER));
    frame.setSize(400,400); // dimensions of the gif.(800x600)
    frame.setUndecorated(true); // removing the minimize and shit..
    frame.setResizable(false); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

So basically after this code is executed for about 10 seconds it would jump to another class that contains another frame called login.java .所以基本上在这段代码执行大约 10 秒后,它会跳转到另一个包含另一个名为 login.java 的框架的类。

In general you can use a Swing Timer to schedule an event.通常,您可以使用Swing Timer来安排事件。

Read the section from the Swing tutorial onHow to Use Swing Timers .阅读 Swing 教程中关于如何使用 Swing 计时器的部分

However, this is not the best solution!然而,这并不是最好的解决方案!

i don't want to use splash我不想使用飞溅

Why are you trying to reinvent the wheel?你为什么要重新发明轮子? Use Swing the way it was designed to be used.按照设计使用的方式使用 Swing。

A splash screen is designed for this purpose and will initially load faster.启动画面就是为此目的而设计的,最初加载速度会更快。

The splash screen can be configured to automatically close after the specified time.启动画面可以配置为在指定时间后自动关闭。

Read the section from the Swing tutorial on How to Create a Splash Screen for a working example.阅读 Swing 教程中有关如何创建启动画面的部分以获取工作示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM