ludc
2024-09-14 36c2449aec5b51e5ed4e5c6841154b746060e09a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.vci.client.ui.swing;
 
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
 
import com.vci.client.ui.locale.LocaleDisplay;
 
/**
 * 继承JDialog,提示用户关闭整个应用的对话框,如果用户选择退出,则此程序自动关闭本应用,否则
 * 此提示对话框消失,主程序当前上下文不发生变化。
 */
public class WindowClosedDialog extends JDialog {
 
    /**
     * 
     */
    private static final long serialVersionUID = 8657389605176951961L;
    private JLabel textLabel = new JLabel();
    private JButton OKButton = new JButton();
    private JButton cancelButton = new JButton();
    private int status = 0;
    
    public WindowClosedDialog(Frame frame) {
        this(frame, "", true);
    }
    
    public WindowClosedDialog(Frame frame, String title, boolean modal) {
        super(frame, "", modal);
        this.setTitle(LocaleDisplay.getI18nString("rmip.framework.exit.system", "RMIPFramework", getLocale()));
        try {
            init();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    private void init() throws Exception {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation( (screenSize.width - 220) / 2,
                         (screenSize.height - 130) / 2);
        this.setSize(new Dimension(220, 130));
        this.setResizable(false);
        textLabel.setText(LocaleDisplay.getI18nString("rmip.framework.exit.confirm", "RMIPFramework", getLocale()));
        OKButton.setText(LocaleDisplay.getI18nString("rmip.framework.button.confirm", "RMIPFramework", getLocale()));
        cancelButton.setText(LocaleDisplay.getI18nString("rmip.framework.button.cancel", "RMIPFramework", getLocale()));
        
        OKButton.addActionListener(new ActionListener() {
 
            public void actionPerformed(ActionEvent e) {
                OKButton_ActionPerformed(e);
            }
        });
        
        cancelButton.addActionListener(new ActionListener() {
 
            public void actionPerformed(ActionEvent e) {
                cancelButton_ActionPerformed(e);
            }
        });
        
        textLabel.setBounds(new Rectangle(20,20,160,25));
        OKButton.setBounds(new Rectangle(20,60,80,25));
        cancelButton.setBounds(new Rectangle(110,60,80,25));
        
        Container c = this.getContentPane();
        c.setLayout(null);
        c.add(textLabel);
        c.add(OKButton);
        c.add(cancelButton);
    }
    
    private void OKButton_ActionPerformed(ActionEvent e) {
        this.status = 1;
        this.dispose();
//        System.exit(0);
    }
    
    private void cancelButton_ActionPerformed(ActionEvent e) {
        this.status =0 ;
        this.dispose();
    }
 
    public int getStatus() {
        return status;
    }
 
    
}