我的代码有一个小问题。我只是希望如果表单的构造函数部分不满足条件,则不显示 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}
}
最佳答案
做这样的事情
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);
}
}
}
关于java - 在构造函数中关闭 Jform,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30245023/