1 7 package javax.swing; 8 9 import java.util.EventListener ; 10 11 import java.awt.*; 12 import java.awt.event.*; 13 import java.awt.image.*; 14 15 import javax.swing.plaf.*; 16 import javax.swing.event.*; 17 import javax.accessibility.*; 18 19 import java.io.ObjectOutputStream ; 20 import java.io.ObjectInputStream ; 21 import java.io.IOException ; 22 23 24 46 public class JButton extends AbstractButton implements Accessible { 47 48 52 private static final String uiClassID = "ButtonUI"; 53 54 57 public JButton() { 58 this(null, null); 59 } 60 61 66 public JButton(Icon icon) { 67 this(null, icon); 68 } 69 70 75 public JButton(String text) { 76 this(text, null); 77 } 78 79 87 public JButton(Action a) { 88 this(); 89 setAction(a); 90 } 91 92 98 public JButton(String text, Icon icon) { 99 setModel(new DefaultButtonModel ()); 101 102 init(text, icon); 104 } 105 106 112 public void updateUI() { 113 setUI((ButtonUI)UIManager.getUI(this)); 114 } 115 116 117 128 public String getUIClassID() { 129 return uiClassID; 130 } 131 132 133 147 public boolean isDefaultButton() { 148 JRootPane root = SwingUtilities.getRootPane(this); 149 if (root != null) { 150 return root.getDefaultButton() == this; 151 } 152 return false; 153 } 154 155 163 public boolean isDefaultCapable() { 164 return defaultCapable; 165 } 166 167 184 public void setDefaultCapable(boolean defaultCapable) { 185 boolean oldDefaultCapable = this.defaultCapable; 186 this.defaultCapable = defaultCapable; 187 firePropertyChange("defaultCapable", oldDefaultCapable, defaultCapable); 188 } 189 190 197 public void removeNotify() { 198 JRootPane root = SwingUtilities.getRootPane(this); 199 if (root != null && root.getDefaultButton() == this) { 200 root.setDefaultButton(null); 201 } 202 super.removeNotify(); 203 } 204 205 219 protected void configurePropertiesFromAction(Action a) { 220 super.configurePropertiesFromAction(a); 221 } 222 223 227 private void writeObject(ObjectOutputStream s) throws IOException { 228 s.defaultWriteObject(); 229 if (getUIClassID().equals(uiClassID)) { 230 byte count = JComponent.getWriteObjCounter(this); 231 JComponent.setWriteObjCounter(this, --count); 232 if (count == 0 && ui != null) { 233 ui.installUI(this); 234 } 235 } 236 } 237 238 239 248 protected String paramString() { 249 String defaultCapableString = (defaultCapable ? "true" : "false"); 250 251 return super.paramString() + 252 ",defaultCapable=" + defaultCapableString; 253 } 254 255 256 260 273 public AccessibleContext getAccessibleContext() { 274 if (accessibleContext == null) { 275 accessibleContext = new AccessibleJButton(); 276 } 277 return accessibleContext; 278 } 279 280 295 protected class AccessibleJButton extends AccessibleAbstractButton { 296 297 304 public AccessibleRole getAccessibleRole() { 305 return AccessibleRole.PUSH_BUTTON; 306 } 307 } } 309 | Popular Tags |