我对代码有个小问题。我只想在form.Outside的构造函数部分不满足条件的情况下不显示J表单--构造函数dispose()、返回和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}
}发布于 2015-05-14 18:53:21
做这样的事
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);
}
}
}发布于 2015-05-14 19:03:35
正如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);
}
}
}https://stackoverflow.com/questions/30245023
复制相似问题