OSDN Git Service

381122fa3cd952f5ff697a9b690930b30d313354
[hayashilib/hayashi.git] / src / hayashi / yuu / tools / gui / QuitDialog.java
1 package hayashi.yuu.tools.gui;
2
3 import java.awt.Font;
4 import java.awt.Rectangle;
5 import java.awt.Toolkit;
6 import java.awt.Window;
7 import java.awt.event.WindowEvent;
8 import java.awt.event.WindowListener;
9
10 import javax.swing.JButton;
11 import javax.swing.JDialog;
12 import javax.swing.JFrame;
13 import javax.swing.JLabel;
14
15 public class QuitDialog extends JDialog implements WindowListener
16 {
17     JButton yesButton;
18     JButton noButton;
19     JLabel label1;
20
21     public QuitDialog(JFrame parent, boolean modal) {
22         super(parent, modal);
23         addWindowListener((WindowListener) this);
24         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
25
26         setLayout(null);
27         setSize(getInsets().left + getInsets().right + 337, getInsets().top + getInsets().bottom + 135);
28         
29         yesButton = new JButton("  終了  ");
30         yesButton.addActionListener(new java.awt.event.ActionListener() {
31                 public void actionPerformed(java.awt.event.ActionEvent evt) {
32                 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent((Window)getParent(), 201));
33                 System.exit(0);
34                 }
35         });
36         yesButton.setBounds(getInsets().left + 72, getInsets().top + 80, 79, 22);
37         yesButton.setFont(new Font("Dialog", 1, 12));
38         add(yesButton);
39
40         noButton = new JButton("キャンセル");
41         noButton.addActionListener(new java.awt.event.ActionListener() {
42                 public void actionPerformed(java.awt.event.ActionEvent evt) {
43                         Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent(QuitDialog.this, WindowEvent.WINDOW_CLOSING));
44                         setVisible(false);
45                 }
46         });
47         noButton.setBounds(getInsets().left + 185, getInsets().top + 80, 99, 22);
48         noButton.setFont(new Font("Dialog", 1, 12));
49         add(noButton);
50         
51         label1 = new JLabel("プログラムを終了します。", JLabel.CENTER);
52         label1.setBounds(78, 33, 180, 23);
53         add(label1);
54         setTitle("プログラムの終了");
55         setResizable(false);
56         setVisible(true);
57     }
58
59     public void setVisible(boolean b) {
60         if(b) {
61             Rectangle bounds = getParent().getBounds();
62             Rectangle abounds = getBounds();
63             setLocation(bounds.x + (bounds.width - abounds.width) / 2, bounds.y + (bounds.height - abounds.height) / 2);
64         }
65         super.setVisible(b);
66     }
67
68
69         public void windowActivated(WindowEvent e) {
70         }
71
72         public void windowClosed(WindowEvent e) {
73                 setVisible(false);
74         }
75
76         public void windowClosing(WindowEvent e) {
77                 setVisible(false);
78         }
79
80         public void windowDeactivated(WindowEvent e) {
81         }
82
83         public void windowDeiconified(WindowEvent e) {
84         }
85
86         public void windowIconified(WindowEvent e) {
87         }
88
89         public void windowOpened(WindowEvent e) {
90         }
91 }