Java 如何记住从其他帧选中的复选框

Java 如何记住从其他帧选中的复选框,java,swing,jframe,multiple-instances,jcheckbox,Java,Swing,Jframe,Multiple Instances,Jcheckbox,我有两个jframe,一个是用于调用复选框框架的主框架,另一个是包含复选框的jframe MainFrame.java 如何在主框架再次调用复选框框架后记住上一个复选框 CheckBox.java 下面是我的按钮操作代码: private void btn_callCheckBoxActionPerformed( java.awt.event.ActionEvent evt) { //call c

我有两个jframe,一个是用于调用复选框框架的主框架,另一个是包含复选框的jframe

MainFrame.java

如何在主框架再次调用复选框框架后记住上一个复选框

CheckBox.java

下面是我的按钮操作代码:

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

    //call checkbox window
    CheckBoxWindow cbw = new CheckBoxWindow();
    cbw.setVisible(true);
    cbw.setEnabled(true);

    this.setVisible(true);
    this.setEnabled(false);

}    
从复选框框调用大型机

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

    //call main frame window
    MainPage mp = new MainPage();
    mp.setVisible(true);
    mp.setEnabled(true);
    this.setEnabled(false);
    this.setVisible(false);
}

你有多种选择

1-不要每次单击按钮时都创建新窗口。将窗口保存在变量中,并使用
setVisible(true)
setVisible(false)
显示/隐藏它们。如果隐藏复选框框并再次显示,则复选框将处于关闭前的状态

这是这样的吗

 public MainPage() {
     this.checkWindow = new CheckWindow()
 }

 private void btn_callCheckBoxActionPerformed(java.awt.event.ActionEvent evt)  {                                         
        // show window
        this.checkWindow.setVisible(true);
        this.checkWindow.setEnabled(true);

        this.setVisible(true);
        this.setEnabled(false);
  }  

2.-使用java的

保存和检索复选框的值您有多个选项

1-不要每次单击按钮时都创建新窗口。将窗口保存在变量中,并使用
setVisible(true)
setVisible(false)
显示/隐藏它们。如果隐藏复选框框并再次显示,则复选框将处于关闭前的状态

这是这样的吗

 public MainPage() {
     this.checkWindow = new CheckWindow()
 }

 private void btn_callCheckBoxActionPerformed(java.awt.event.ActionEvent evt)  {                                         
        // show window
        this.checkWindow.setVisible(true);
        this.checkWindow.setEnabled(true);

        this.setVisible(true);
        this.setEnabled(false);
  }  

2.-使用java的

保存和检索复选框的值您有多个选项

1-不要每次单击按钮时都创建新窗口。将窗口保存在变量中,并使用
setVisible(true)
setVisible(false)
显示/隐藏它们。如果隐藏复选框框并再次显示,则复选框将处于关闭前的状态

这是这样的吗

 public MainPage() {
     this.checkWindow = new CheckWindow()
 }

 private void btn_callCheckBoxActionPerformed(java.awt.event.ActionEvent evt)  {                                         
        // show window
        this.checkWindow.setVisible(true);
        this.checkWindow.setEnabled(true);

        this.setVisible(true);
        this.setEnabled(false);
  }  

2.-使用java的

保存和检索复选框的值您有多个选项

1-不要每次单击按钮时都创建新窗口。将窗口保存在变量中,并使用
setVisible(true)
setVisible(false)
显示/隐藏它们。如果隐藏复选框框并再次显示,则复选框将处于关闭前的状态

这是这样的吗

 public MainPage() {
     this.checkWindow = new CheckWindow()
 }

 private void btn_callCheckBoxActionPerformed(java.awt.event.ActionEvent evt)  {                                         
        // show window
        this.checkWindow.setVisible(true);
        this.checkWindow.setEnabled(true);

        this.setVisible(true);
        this.setEnabled(false);
  }  

2.-使用java的

保存和检索复选框的值这里有一种方法可以执行您想要的操作:

在复选框窗口中创建一个方法,该方法将返回所选内容的布尔值

private boolean chck1=false;
private boolean chck2=false;

public boolean getCheckBoxOneState(){
    return chck1;
}
private void btn_callMainFrameActionPerformed(java.awt.event.ActionEvent evt) {                                         
    chck1 = jCheckBox1.isSelected();
    chck2 = jCheckBox2.isSelected();
//call main frame window
MainPage mp = new MainPage();
mp.setVisible(true);
mp.setEnabled(true);
this.setEnabled(false);
this.setVisible(false);}
然后在您的主页中,只需实例另一个框架,并调用返回复选框值的方法

boolean chck1State = new CheckBoxWindow().getCheckBoxOne();

这里有一种方法可以满足您的需求:

在复选框窗口中创建一个方法,该方法将返回所选内容的布尔值

private boolean chck1=false;
private boolean chck2=false;

public boolean getCheckBoxOneState(){
    return chck1;
}
private void btn_callMainFrameActionPerformed(java.awt.event.ActionEvent evt) {                                         
    chck1 = jCheckBox1.isSelected();
    chck2 = jCheckBox2.isSelected();
//call main frame window
MainPage mp = new MainPage();
mp.setVisible(true);
mp.setEnabled(true);
this.setEnabled(false);
this.setVisible(false);}
然后在您的主页中,只需实例另一个框架,并调用返回复选框值的方法

boolean chck1State = new CheckBoxWindow().getCheckBoxOne();

这里有一种方法可以满足您的需求:

在复选框窗口中创建一个方法,该方法将返回所选内容的布尔值

private boolean chck1=false;
private boolean chck2=false;

public boolean getCheckBoxOneState(){
    return chck1;
}
private void btn_callMainFrameActionPerformed(java.awt.event.ActionEvent evt) {                                         
    chck1 = jCheckBox1.isSelected();
    chck2 = jCheckBox2.isSelected();
//call main frame window
MainPage mp = new MainPage();
mp.setVisible(true);
mp.setEnabled(true);
this.setEnabled(false);
this.setVisible(false);}
然后在您的主页中,只需实例另一个框架,并调用返回复选框值的方法

boolean chck1State = new CheckBoxWindow().getCheckBoxOne();

这里有一种方法可以满足您的需求:

在复选框窗口中创建一个方法,该方法将返回所选内容的布尔值

private boolean chck1=false;
private boolean chck2=false;

public boolean getCheckBoxOneState(){
    return chck1;
}
private void btn_callMainFrameActionPerformed(java.awt.event.ActionEvent evt) {                                         
    chck1 = jCheckBox1.isSelected();
    chck2 = jCheckBox2.isSelected();
//call main frame window
MainPage mp = new MainPage();
mp.setVisible(true);
mp.setEnabled(true);
this.setEnabled(false);
this.setVisible(false);}
然后在您的主页中,只需实例另一个框架,并调用返回复选框值的方法

boolean chck1State = new CheckBoxWindow().getCheckBoxOne();

谢谢你的帮助。没有你们就解决不了。我成功了。我只需要隐藏窗口,避免在单击按钮时创建新窗口

\*
 *From Class MainFrame
 */
public MainFrame(){

this.CheckBox = new CheckBox(this);
}

//button action to show checkbox frame
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){

CheckBox.setVisible(true);
}

\***********************************************************************\

\*
* From class CheckBox
\*

public CheckBox(JFrame mainFrame) {
this.MainFrame = MainFrame;
}

//button action to show MainFrame frame
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){
MainFrame.setVisible();
}

谢谢你的帮助。没有你们就解决不了。我成功了。我只需要隐藏窗口,避免在单击按钮时创建新窗口

\*
 *From Class MainFrame
 */
public MainFrame(){

this.CheckBox = new CheckBox(this);
}

//button action to show checkbox frame
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){

CheckBox.setVisible(true);
}

\***********************************************************************\

\*
* From class CheckBox
\*

public CheckBox(JFrame mainFrame) {
this.MainFrame = MainFrame;
}

//button action to show MainFrame frame
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){
MainFrame.setVisible();
}

谢谢你的帮助。没有你们就解决不了。我成功了。我只需要隐藏窗口,避免在单击按钮时创建新窗口

\*
 *From Class MainFrame
 */
public MainFrame(){

this.CheckBox = new CheckBox(this);
}

//button action to show checkbox frame
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){

CheckBox.setVisible(true);
}

\***********************************************************************\

\*
* From class CheckBox
\*

public CheckBox(JFrame mainFrame) {
this.MainFrame = MainFrame;
}

//button action to show MainFrame frame
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){
MainFrame.setVisible();
}

谢谢你的帮助。没有你们就解决不了。我成功了。我只需要隐藏窗口,避免在单击按钮时创建新窗口

\*
 *From Class MainFrame
 */
public MainFrame(){

this.CheckBox = new CheckBox(this);
}

//button action to show checkbox frame
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){

CheckBox.setVisible(true);
}

\***********************************************************************\

\*
* From class CheckBox
\*

public CheckBox(JFrame mainFrame) {
this.MainFrame = MainFrame;
}

//button action to show MainFrame frame
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){
MainFrame.setVisible();
}

肯定有比使用数据库更好的方法吗?在某些类(甚至同一类)中,保存一个
地图
或一些相关集合,其中包含当带有复选框的窗口被导航离开时单击了哪些按钮的信息。肯定有比使用数据库更好的方法吗?在某些类中(甚至是同一个类),保存一个
地图
或一些相关集合,其中包含当带有复选框的窗口被导航离开时单击哪些按钮的信息。肯定有更好的方法,而不是在某些类(甚至同一个类)中使用数据库,保存一个
地图
或一些相关集合,其中包含当带有复选框的窗口被导航离开时单击了哪些按钮的信息。肯定有更好的方法,而不是在某些类(甚至同一类)中使用数据库,保存一个
地图
或一些相关集合,其中包含当带有复选框的窗口被导航离开时单击了哪些按钮的相关信息。