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; } }