ptionPane.YES_NO_OPTION);
if(result == JOptionPane.YES_OPTION){
//泌惚僉夲YES?住喇貧蚊譜崔議購液侃尖
super.doDefaultCloseAction();
}
}
悳議霞編旗鷹泌和?
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
/** *//***
* JFrame才JInternalFrame購液念枠鳩範頁倦購液
* @author kissjava
* www.blogjava.net/kissjava
* **/
public class CloseFrameDemo extends JFrame{
public CloseFrameDemo(){
this.setTitle("CloseFrameDemo");
jbInit();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(800, 800);
this.setVisible(true);
}
private void jbInit(){
JDesktopPane desktop = new JDesktopPane();
JInternalFrame internalFrame = this.createJInternalFrame();
JButton btn = new JButton("DEMO");
internalFrame.add(btn, "Center");
desktop.add(internalFrame, JDesktopPane.PALETTE_LAYER);
internalFrame.setSize(400,400);
internalFrame.setVisible(true);
this.add(desktop, "Center");
}
private JInternalFrame createJInternalFrame(){
JInternalFrame internalFrame = new JInternalFrame("JInternalFrame Close Demo", true, true, true, true){
/** *//***
* 嶷亟緩圭隈斑喘薩鳩範頁倦俶勣購液
* */
@Override
public void doDefaultCloseAction(){
//購液議戻幣僉夲
int result= JOptionPane.showConfirmDialog(
this,
("鳩範勣購液JInternalFrame宅?"),
("購液"),
JOptionPane.YES_NO_OPTION);
if(result == JOptionPane.YES_OPTION){
//泌惚僉夲YES?住喇貧蚊譜崔議購液侃尖
super.doDefaultCloseAction();
}
}
};
return internalFrame;
}
/** *//***
* 嶷亟緩圭隈斑喘薩鳩範頁倦俶勣購液
* */
@Override
protected void processWindowEvent(WindowEvent e) {
|