2015-05-14 35 views
0

我对代码有一个小问题。我只是希望如果在表单的构造函数部分中没有满足条件,则不会显示Jform。构造函数dispose(),return和setVisible(false)都可以正常工作。我曾尝试this.dispose();并返回;和this.setVisible(false);但表单仍然显示。用System.exit(0);它关闭了完整的应用程序。如果有人能帮助我,我会很感激。在构造函数中关闭Jform

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} 
} 
+0

*“Closing Jform ..”* J2SE API中没有这样的类。不要像你的IDE那样说话。 –

回答

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

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