Newer
Older
adjustgpx-gui / src / main / java / osm / jp / gpx / matchtime / gui / QuitDialog.java
@haya4 haya4 on 8 Mar 2020 3 KB JDK1.8
  1. package osm.jp.gpx.matchtime.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. import java.util.ResourceBundle;
  10.  
  11. import javax.swing.JButton;
  12. import javax.swing.JDialog;
  13. import javax.swing.JFrame;
  14. import javax.swing.JLabel;
  15.  
  16. @SuppressWarnings("serial")
  17. public class QuitDialog extends JDialog implements WindowListener
  18. {
  19. JButton yesButton;
  20. JButton noButton;
  21. JLabel label1;
  22.  
  23. public QuitDialog(JFrame parent, boolean modal) {
  24. super(parent, modal);
  25. ResourceBundle i18n = ResourceBundle.getBundle("i18n");
  26.  
  27. addWindowListener((WindowListener) this);
  28. setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  29.  
  30. setLayout(null);
  31. setSize(getInsets().left + getInsets().right + 337, getInsets().top + getInsets().bottom + 135);
  32. yesButton = new JButton(String.format(" %s ", i18n.getString("dialog.quit")));
  33. yesButton.addActionListener(new java.awt.event.ActionListener() {
  34. @Override
  35. public void actionPerformed(java.awt.event.ActionEvent evt) {
  36. Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent((Window)getParent(), 201));
  37. System.exit(0);
  38. }
  39. });
  40. yesButton.setBounds(getInsets().left + 72, getInsets().top + 80, 79, 22);
  41. yesButton.setFont(new Font("Dialog", 1, 12));
  42. add(yesButton);
  43.  
  44. noButton = new JButton(i18n.getString("dialog.cancel"));
  45. noButton.addActionListener(new java.awt.event.ActionListener() {
  46. @Override
  47. public void actionPerformed(java.awt.event.ActionEvent evt) {
  48. Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent(QuitDialog.this, WindowEvent.WINDOW_CLOSING));
  49. setVisible(false);
  50. }
  51. });
  52. noButton.setBounds(getInsets().left + 185, getInsets().top + 80, 99, 22);
  53. noButton.setFont(new Font("Dialog", 1, 12));
  54. add(noButton);
  55. label1 = new JLabel(i18n.getString("dialog.msg1"), JLabel.CENTER);
  56. label1.setBounds(78, 33, 180, 23);
  57. add(label1);
  58. setTitle(i18n.getString("dialog.msg1"));
  59. setResizable(false);
  60. setVisible(true);
  61. }
  62.  
  63. @Override
  64. public void setVisible(boolean b) {
  65. if(b) {
  66. Rectangle bounds = getParent().getBounds();
  67. Rectangle abounds = getBounds();
  68. setLocation(bounds.x + (bounds.width - abounds.width) / 2, bounds.y + (bounds.height - abounds.height) / 2);
  69. }
  70. super.setVisible(b);
  71. }
  72.  
  73.  
  74. @Override
  75. public void windowActivated(WindowEvent e) {
  76. }
  77.  
  78. @Override
  79. public void windowClosed(WindowEvent e) {
  80. setVisible(false);
  81. }
  82.  
  83. @Override
  84. public void windowClosing(WindowEvent e) {
  85. setVisible(false);
  86. }
  87.  
  88. @Override
  89. public void windowDeactivated(WindowEvent e) {
  90. }
  91.  
  92. @Override
  93. public void windowDeiconified(WindowEvent e) {
  94. }
  95.  
  96. @Override
  97. public void windowIconified(WindowEvent e) {
  98. }
  99.  
  100. @Override
  101. public void windowOpened(WindowEvent e) {
  102. }
  103. }