我想创建一个带有函数的jbutton来调用jframe,但是jbutton必须能够停止调用jframe,如果它已经被调用并存在的话。我们怎么能这样做?
JButtonCallJFrame.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//step 1 - check if jframe already open/called or not
//step 1.a - if true ignore, jbutton do nothing
//step 1.2 - else if false,jbutton called for jframe
ClassWithJFrame cwjFrame = new ClassWithJFrame()
if(cwjFrame is exist){
//DO NOTHING
}
else if(cwjFrame not exist){
cwjFrame.setVisible(true);
}
}
});
答案 0 :(得分:2)
cwjFrame.isVisible() will return true if frame is already visible
if(cwjFrame.isVisible()){
//DO NOTHING
}
else if(!cwjFrame.isVisible()){
cwjFrame.setVisible(true);
}