如何解决重新打开先前关闭的窗口 Java 我的问题:第一个窗口
我开发了一个程序来了解登录的工作原理。我有一个窗口(jFrame),您可以在其中使用“创建新帐户”按钮登录。如果单击此按钮,登录窗口将关闭并创建 acc。窗口(另一个文件)打开。我希望它在您创建帐户后重新打开登录窗口。
我的问题:
我不知道如何重新打开登录窗口。无论是通过重新启动 mainmethod 还是其他什么,你们都希望告诉我。
第一个窗口
public class password extends javax.swing.JFrame {
public password() {
initComponents();
}
private void initComponents() {
jButton1 = new javax.swing.JButton();
[some more Elements...]
jButton1.setText("Create an account");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
[more layoutstuff...]
}
//event where it opens the new window and closes the login window
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
register reg = new register();
reg.register();
dispose();
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(password.class.getName()).log(java.util.logging.Level.SEVERE,null,ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(password.class.getName()).log(java.util.logging.Level.SEVERE,ex);
} catch (illegalaccessexception ex) {
java.util.logging.Logger.getLogger(password.class.getName()).log(java.util.logging.Level.SEVERE,ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(password.class.getName()).log(java.util.logging.Level.SEVERE,ex);
}
java.awt.EventQueue.invokelater(new Runnable() {
public void run() {
new password().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
[more elements...]
}
第二个窗口
public class register extends javax.swing.JFrame {
public register() {
initComponents();
}
private void initComponents() {
jTextField1 = new javax.swing.JTextField();
[again more elements and layoutstuff...]
}
public static void register() {
java.awt.EventQueue.invokelater(new Runnable() {
public void run() {
new register().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
[more elements]
}
请原谅我的问题,但我对编程很陌生。
解决方法
您可以先隐藏登录窗口,稍后再显示,也可以卷起一个新的登录窗口。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。