import java.beans.*;
import javax.swing.*;
import java.awt.*;public class ClosingListener implements VetoableChangeListener{
public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException{
String name=e.getPropertyName();
if(name.equals(JInternalFrame.IS_CLOSED_PROPERTY)){
Component c=(Component)e.getSource();
Boolean oldValue=(Boolean)e.getOldValue();
Boolean newValue=(Boolean)e.getNewValue();
if(oldValue==Boolean.FALSE&&newValue==Boolean.TRUE){
c.setVisible(true);
int select=JOptionPane.showConfirmDialog(c,"真的要退出吗?","系统消息",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if(select==JOptionPane.YES_OPTION){
System.out.println("内部窗体已经关闭!");
}
else{
throw new PropertyVetoException("close cancleled",e);
}
}
}
}
}
在你的内部窗体类中加入
this.addVetoableChangeListener(new ClosingListener());
import javax.swing.*;
import java.awt.*;public class ClosingListener implements VetoableChangeListener{
public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException{
String name=e.getPropertyName();
if(name.equals(JInternalFrame.IS_CLOSED_PROPERTY)){
Component c=(Component)e.getSource();
Boolean oldValue=(Boolean)e.getOldValue();
Boolean newValue=(Boolean)e.getNewValue();
if(oldValue==Boolean.FALSE&&newValue==Boolean.TRUE){
c.setVisible(true);
int select=JOptionPane.showConfirmDialog(c,"真的要退出吗?","系统消息",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if(select==JOptionPane.YES_OPTION){
System.out.println("内部窗体已经关闭!");
}
else{
throw new PropertyVetoException("close cancleled",e);
}
}
}
}
}
在你的内部窗体类中加入
this.addVetoableChangeListener(new ClosingListener());
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货