1 package com.quikj.application.utilities.postinstall; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 6 class YesNoDialog extends Dialog 7 { 8 private Button okButton; 9 private Button cancelButton; 10 11 private boolean selection = false; 12 13 public YesNoDialog (Frame parent, String title, String text, String ok_text, String cancel_text) 14 { 15 super (parent, title, true); 16 17 GridBagLayout gbl = new GridBagLayout(); 18 GridBagConstraints gbc = new GridBagConstraints(); 19 setLayout (gbl); 20 21 Panel panel1 = new Panel(); 22 panel1.setLayout (gbl); 23 24 addToContainer (panel1, 25 gbl, 26 gbc, 27 new Label (text), 28 0, 29 0, 30 1, 31 1, 32 GridBagConstraints.NONE, 33 GridBagConstraints.NORTHWEST, 34 0, 0); 35 36 addToContainer (this, 38 gbl, 39 gbc, 40 panel1, 41 0, 42 0, 43 5, 44 1, 45 GridBagConstraints.BOTH, 46 GridBagConstraints.NORTHWEST, 47 1, 0, 48 new Insets (5, 5, 5, 5)); 49 50 Panel panel2 = new Panel(); 51 panel2.setLayout (gbl); 52 53 okButton = new Button (ok_text); 54 okButton.addActionListener (new OkListener()); 55 addToContainer (panel2, 56 gbl, 57 gbc, 58 okButton, 59 0, 60 0, 61 1, 62 1, 63 GridBagConstraints.NONE, 64 GridBagConstraints.CENTER, 65 0, 0, 66 new Insets (0, 0, 0, 5)); 67 68 if (cancel_text != null) 69 { 70 cancelButton = new Button (cancel_text); 71 cancelButton.addActionListener (new CancelListener()); 72 addToContainer (panel2, 73 gbl, 74 gbc, 75 cancelButton, 76 1, 77 0, 78 1, 79 1, 80 GridBagConstraints.NONE, 81 GridBagConstraints.CENTER, 82 0, 0); 83 } 84 85 addToContainer (this, 87 gbl, 88 gbc, 89 panel2, 90 0, 91 1, 92 1, 93 1, 94 GridBagConstraints.HORIZONTAL, 95 GridBagConstraints.CENTER, 96 1, 0, 97 new Insets (0, 5, 5, 5)); 98 99 pack(); 100 Rectangle pbounds = parent.getBounds(); 101 Point mid = new Point (pbounds.x + (pbounds.width/2), pbounds.y + (pbounds.height/2)); 102 Rectangle bounds = getBounds(); 103 int x = mid.x - (bounds.width/2); 104 int y = mid.y - (bounds.height/2); 105 if (x < 0) x = pbounds.x; 106 if (y < 0) y = pbounds.y; 107 setBounds (x, y, bounds.width, bounds.height); 108 109 show(); 110 } 111 112 public boolean okSelected() 113 { 114 return selection; 115 } 116 117 private void addToContainer (Container cont, 118 GridBagLayout gbl, 119 GridBagConstraints gbc, 120 Component comp, 121 int gridx, 122 int gridy, 123 int gridwidth, 124 int gridheight, 125 int fill, 126 int anchor, 127 int weightx, 128 int weighty, 129 Insets insets) 130 { 131 gbc.gridx = gridx; 132 gbc.gridy = gridy; 133 gbc.gridwidth = gridwidth; 134 gbc.gridheight = gridheight; 135 gbc.fill = fill; 136 gbc.anchor = anchor; 137 gbc.weightx = weightx; 138 gbc.weighty = weighty; 139 140 if (insets != null) 141 { 142 gbc.insets = insets; 143 } 144 145 gbl.setConstraints (comp, gbc); 146 cont.add (comp); 147 } 148 149 private void addToContainer (Container cont, 150 GridBagLayout gbl, 151 GridBagConstraints gbc, 152 Component comp, 153 int gridx, 154 int gridy, 155 int gridwidth, 156 int gridheight, 157 int fill, 158 int anchor, 159 int weightx, 160 int weighty) 161 { 162 addToContainer (cont, gbl, gbc, comp, gridx, gridy, gridwidth, gridheight, 163 fill, anchor, weightx, weighty, null); 164 } 165 166 class CancelListener implements ActionListener 167 { 168 public void actionPerformed (ActionEvent e) 169 { 170 YesNoDialog.this.dispose(); 171 } 172 }; 173 174 class OkListener implements ActionListener 175 { 176 public void actionPerformed (ActionEvent e) 177 { 178 selection = true; 179 YesNoDialog.this.dispose(); 180 } 181 }; 182 } 183 184 185 | Popular Tags |