我试图在5秒后隐藏当前窗口,并显示一个单独的窗口。
我已经添加了一个等待5秒钟的计时器,如代码所示,但是我无法使用this.isVisible(false)访问当前窗口,尽管此代码在按钮上添加时有效。 我还尝试了myProject()。this.isVisible(false),但也给出了我的错误。
可以实现此目的的简单代码替代方案将非常受欢迎。
我还尝试了什么: 我尝试了线程等待,但是一旦开始暂停,它不会完全加载窗口。
预期结果: 5秒后,隐藏当前窗口,并显示下一个窗口
谢谢
package myProject;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Timer;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Splash extends javax.swing.JFrame {
public Splash() {
initComponents();
}
public static void main(String args[]) {
[...default code ...]
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Splash().setVisible(true);
}
});
// code I'm trying to run when the window shows
new java.util.Timer().schedule(
new java.util.TimerTask() {
@Override
public void run() {
// show the next window
WindowShow Show = new WindowShow();
Show.setVisible(true);
// hide this window, DOESN'T WORK
this.setVisible(false);
}
},
5000
);
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
// End of variables declaration
}