-----------在外部类写的checkbox
private JCheckBox createBillCheckBox(){
final JCheckBox box = new JCheckBox("切改单开关");
box.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(box.isSelected()){
HistoryBillsFrm billsDlg = HistoryBillsFrm.getInstance();
billsDlg.setVisible(true);
}else{
HistoryBillsFrm.getInstance().dispose();
//取消当前切改单,解除锁定
LocalBill l = new LocalBill();
PipeLineUtils.status = "0";
l.cancelCurrentBill();
}
}
});
box.setName(CommandConstant.CMD_SHOW_BILL);
box.setPreferredSize(new Dimension(90, 10));
return box;
}
---------------------------写的JFrame的主要部分代码
public class HistoryBillsFrm extends JFrame {
private static HistoryBillsFrm instance = null;
public JScrollPane billListPane;
private JPanel mainPanel;
private JPanel midPane;
private JPanel btmpane;
private JButton detailBtn = new JButton("详细");
private ButtonGroup bg;
LocalBill l;
/**
*
* HistoryBillsFrm
*/
public HistoryBillsFrm(){
PipeLineUtils.status = "1";
initUI();
}
/**
* 单例模式
* Author:yruidong
* 2012-5-29 下午04:04:10
* @return
* @return HistoryBillsDlg
*/
public static HistoryBillsFrm getInstance() {
if (instance == null) {
try {
instance = new HistoryBillsFrm();
} catch (Exception ex) {
SwingExceptionCatchTemplate s=new SwingExceptionCatchTemplate(ex);
s.throwException();
}
}
return instance;
}
/**
* 初始化UI
* Author:yruidong
* 2012-6-1 上午10:26:37
* @return void
*/
private void initUI(){
//当前切改单状态栏,设置为可用
l = new LocalBill();
//本地文件与数据库数据进行校验,移除已经下发、归档的
l.checkClientData();
mainPanel = new JPanel(new BorderLayout());
btmpane = new JPanel();
btmpane.setLayout(new CounterFlowLayout());
detailBtn.setPreferredSize(new Dimension(70, 25));
btmpane.add(detailBtn);
detailBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
OptBillsDlg billsDlg = new OptBillsDlg();
billsDlg.setModal(true);
billsDlg.setVisible(true);
}
});
this.add(mainPanel);
this.setTitle("光缆切改单");
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setResizable(false);
this.pack();
this.setSize(280, 500);
this.setLocationRelativeTo(null);
//激活窗口事件
this.enableEvents(AWTEvent.WINDOW_EVENT_MASK);
//this.setVisible(true);
initSPUI();
}/**
* 重写窗口关闭方法
*/
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING){
int confirmRes = SwingUtils.showConfirmDialog(HistoryBillsFrm.this, "确定要退出切改模式吗?", JOptionPane.OK_CANCEL_OPTION);
if(confirmRes != JOptionPane.OK_OPTION){
//直接返回,阻止默认动作,阻止窗口关闭
return;
}else{
HistoryBillsFrm.this.invalidate();
int n = JGISWin.toolBar.getComponentCount();
for (int i = 0; i < n; i++) {
Component c = JGISWin.toolBar.getComponent(i);
if (c instanceof JCheckBox) {
if(c.getName().equals("optBill")){
JCheckBox tmp = (JCheckBox) c;
tmp.setSelected(false);
}
}
}
//取消当前切改单,解除锁定
PipeLineUtils.status = "0";
l.cancelCurrentBill();
PipeLineUtils.realeaseRes(HistoryBillsFrm.this);
super.processWindowEvent(e); //该语句会执行窗口事件的默认动作(如:隐藏)
}
}
}
发现在外部调用那个dispose方法,没有真正关闭,窗体实际上是被隐藏了
private JCheckBox createBillCheckBox(){
final JCheckBox box = new JCheckBox("切改单开关");
box.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(box.isSelected()){
HistoryBillsFrm billsDlg = HistoryBillsFrm.getInstance();
billsDlg.setVisible(true);
}else{
HistoryBillsFrm.getInstance().dispose();
//取消当前切改单,解除锁定
LocalBill l = new LocalBill();
PipeLineUtils.status = "0";
l.cancelCurrentBill();
}
}
});
box.setName(CommandConstant.CMD_SHOW_BILL);
box.setPreferredSize(new Dimension(90, 10));
return box;
}
---------------------------写的JFrame的主要部分代码
public class HistoryBillsFrm extends JFrame {
private static HistoryBillsFrm instance = null;
public JScrollPane billListPane;
private JPanel mainPanel;
private JPanel midPane;
private JPanel btmpane;
private JButton detailBtn = new JButton("详细");
private ButtonGroup bg;
LocalBill l;
/**
*
* HistoryBillsFrm
*/
public HistoryBillsFrm(){
PipeLineUtils.status = "1";
initUI();
}
/**
* 单例模式
* Author:yruidong
* 2012-5-29 下午04:04:10
* @return
* @return HistoryBillsDlg
*/
public static HistoryBillsFrm getInstance() {
if (instance == null) {
try {
instance = new HistoryBillsFrm();
} catch (Exception ex) {
SwingExceptionCatchTemplate s=new SwingExceptionCatchTemplate(ex);
s.throwException();
}
}
return instance;
}
/**
* 初始化UI
* Author:yruidong
* 2012-6-1 上午10:26:37
* @return void
*/
private void initUI(){
//当前切改单状态栏,设置为可用
l = new LocalBill();
//本地文件与数据库数据进行校验,移除已经下发、归档的
l.checkClientData();
mainPanel = new JPanel(new BorderLayout());
btmpane = new JPanel();
btmpane.setLayout(new CounterFlowLayout());
detailBtn.setPreferredSize(new Dimension(70, 25));
btmpane.add(detailBtn);
detailBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
OptBillsDlg billsDlg = new OptBillsDlg();
billsDlg.setModal(true);
billsDlg.setVisible(true);
}
});
this.add(mainPanel);
this.setTitle("光缆切改单");
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setResizable(false);
this.pack();
this.setSize(280, 500);
this.setLocationRelativeTo(null);
//激活窗口事件
this.enableEvents(AWTEvent.WINDOW_EVENT_MASK);
//this.setVisible(true);
initSPUI();
}/**
* 重写窗口关闭方法
*/
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING){
int confirmRes = SwingUtils.showConfirmDialog(HistoryBillsFrm.this, "确定要退出切改模式吗?", JOptionPane.OK_CANCEL_OPTION);
if(confirmRes != JOptionPane.OK_OPTION){
//直接返回,阻止默认动作,阻止窗口关闭
return;
}else{
HistoryBillsFrm.this.invalidate();
int n = JGISWin.toolBar.getComponentCount();
for (int i = 0; i < n; i++) {
Component c = JGISWin.toolBar.getComponent(i);
if (c instanceof JCheckBox) {
if(c.getName().equals("optBill")){
JCheckBox tmp = (JCheckBox) c;
tmp.setSelected(false);
}
}
}
//取消当前切改单,解除锁定
PipeLineUtils.status = "0";
l.cancelCurrentBill();
PipeLineUtils.realeaseRes(HistoryBillsFrm.this);
super.processWindowEvent(e); //该语句会执行窗口事件的默认动作(如:隐藏)
}
}
}
发现在外部调用那个dispose方法,没有真正关闭,窗体实际上是被隐藏了
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货