在构造函数中关闭 Jform

Closing Jform in the constructor

我的代码有一个小问题。如果 form.Outside 的构造函数部分不满足条件,我只希望不显示 Jform,dispose()、return 和 setVisible(false) 都可以正常工作。我试过 this.dispose();和 return;和 this.setVisible(假);但表格仍然显示。用 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}
}

做这样的事情

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);
       } 
   }
}

正如 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);
   } 
}
}