gpt4 book ai didi

java - 如何取消隐藏/调用带有两个参数的 jframe 类

转载 作者:行者123 更新时间:2023-11-30 03:57:32 25 4
gpt4 key购买 nike

我目前的问题是我通过使用 this.setVisible(false) 隐藏了我的 jframe1 并调用了 jframe2。但我如何再次转到同一个 jframe1 ?我可以设置 jframe1.setVisible(true) 但这将调用一个新的 jframe1。

我隐藏的前一个 jframe1 有我从登录表单中提取的 mysql 数据。现在你看,我的问题是,如果我将 jframe1 设置为 jframe2 中的 setVisible(true) ,它实际上会运行新的 jframe1 ,并且之前具有登录表单的所有先前数据都将丢失。

供您引用,我的 jframe1 有 2 个覆盖类,jframe1() 和 jframe1(String getUsername, String getPassword)。我正在使用 jframe1(String getUsername, String getPassword) 从登录表单调用 jframe1。

示例情况来自 jframe1(String getUsername, String getPassword)

//button to move from jframe1 to jframe2   (at jframe1)
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {

jframe2 frame2 = new jframe2();
this.setVisible(false); // i hide jframe1(String , String) and call jframe2
// i use this.setVissible(false) because i dont know how to put
// jframe1(2 parameter) with setVisible().

frame2.setVisible(true);// call jframe2

}

取消隐藏并再次从 jframe2 调用 jframe1(String, String)

 private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {                                          

jframe1 frame1 = new jframe1(); //i have no idea how create jframe1 instance
//with 2 parameter, perhap this is the reason
// i failed to call previous jframe1

mf.setVisible(true); // unhide and call jframe1, unfortunately it will
// create new jframe1 form, i have no idea how to
// call/unhide the previous jframe1

this.setVisible(false); //hide jframe2

最佳答案

我不确定这是否是您正在寻找的。听起来,您希望能够从另一个类中恢复隐藏的 (frame1.setVisible(false);) 窗口。

为此,您必须提供对您的frame1 的引用的访问权限。然后您就可以按原样恢复窗口了。

您的主窗口:

public class Window1 extends JFrame {             
private final String username;
private final String password;


public Window1 (final String username, final String password) {
this.username = username;
this.password = password;

// do initial stuff for you frame here

this.setVisible(true);
}

// have to implement actual button action listener here
private onButtonClick() {
final Window2 = new Window2(this);

this.setVisible(false);
}

}

你的第二个窗口(也许是一个对话框或其他什么?):

public class Window2 extends JFrame {
private final JFrame firstWindow;

public Window2(final JFrame firstWindow) {
if (firstWindow == null)
throw new IllegalArgumentException("No main window specified");

this.firstWindow = firstWindow;

// do initial stuff for your temp window here

this.setVisible(true);
}


// have to implement actual button action listener here
private onButtonClick() {
firstWindow.setVisible(true);
this.dispose();
}
}

关于java - 如何取消隐藏/调用带有两个参数的 jframe 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22803122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com