【问题标题】:Closing Jform in the constructor在构造函数中关闭 Jform
【发布时间】:2015-05-14 18:48:43
【问题描述】:

我的代码有一个小问题。如果表单的构造函数部分不满足条件,我只想不显示 Jform。在构造函数之外,dispose()、return 和 setVisible(false) 都可以正常工作。我试过 this.dispose();并返回;和 this.setVisible(false);但表格仍然显示。使用 System.exit(0);它关闭了整个应用程序。如果有人可以帮助我,我将不胜感激。

public class OrderGUI extends javax.swing.JFrame {

public OrderGUI(Customer cust, Date dt, Time t) throws FileNotFoundException, IOException, ClassNotFoundException {
    this();
if(condition)
{
/////do not initialize the Jform
}else{//// run rest of the code}
}

【问题讨论】:

  • "Closing Jform.." J2SE API 中没有这样的类。不要像你的 IDE 那样说话。

标签: java swing netbeans swingx jform


【解决方案1】:

做这样的事情

public class OrderGUI extends javax.swing.JFrame {
    public OrderGUI(Customer cust, Date dt, Time t) throws FileNotFoundException, IOException, ClassNotFoundException {
       this();
    }

   @Override
   public void setVisible(boolean val){
       if(!condition){
           super.setVisible(val);
       } 
   }
}

【讨论】:

    【解决方案2】:

    正如 Subash 指出的那样,这非常有效。

    public class OrderGUI extends javax.swing.JFrame {
    public OrderGUI(Customer cust, Date dt, Time t) throws FileNotFoundException, IOException, ClassNotFoundException {
       this();
    }
    
    @Override
    public void setVisible(boolean val){
       if(!condition){
           super.setVisible(val);
       } 
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-08
      • 2018-05-06
      • 2021-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多