我对代码有一个小问题。我只希望如果在表单的构造函数部分中未满足条件,则不会显示jform。我尝试了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);
}
}
}
正如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);
}
}
}