1 7 package javax.swing; 8 9 import java.awt.*; 10 import java.awt.event.*; 11 import java.applet.Applet ; 12 import java.beans.PropertyChangeListener ; 13 import java.util.Locale ; 14 import java.util.Vector ; 15 import java.io.Serializable ; 16 import javax.accessibility.*; 17 18 70 public class JApplet extends Applet implements Accessible, RootPaneContainer 71 { 72 76 protected JRootPane rootPane; 77 78 87 protected boolean rootPaneCheckingEnabled = false; 88 89 100 public JApplet() throws HeadlessException { 101 super(); 102 TimerQueue q = TimerQueue.sharedInstance(); 104 if(q != null) { 105 synchronized(q) { 106 if(!q.running) 107 q.start(); 108 } 109 } 110 111 117 setForeground(Color.black); 118 setBackground(Color.white); 119 120 setLocale( JComponent.getDefaultLocale() ); 121 setLayout(new BorderLayout()); 122 setRootPane(createRootPane()); 123 setRootPaneCheckingEnabled(true); 124 125 setFocusTraversalPolicyProvider(true); 126 sun.awt.SunToolkit.checkAndSetPolicy(this, true); 127 128 enableEvents(AWTEvent.KEY_EVENT_MASK); 129 } 130 131 132 133 protected JRootPane createRootPane() { 134 JRootPane rp = new JRootPane (); 135 rp.setOpaque(true); 140 return rp; 141 } 142 143 147 public void update(Graphics g) { 148 paint(g); 149 } 150 151 152 162 public void setJMenuBar(JMenuBar menuBar) { 163 getRootPane().setMenuBar(menuBar); 164 } 165 166 171 public JMenuBar getJMenuBar() { 172 return getRootPane().getMenuBar(); 173 } 174 175 176 188 protected boolean isRootPaneCheckingEnabled() { 189 return rootPaneCheckingEnabled; 190 } 191 192 193 209 protected void setRootPaneCheckingEnabled(boolean enabled) { 210 rootPaneCheckingEnabled = enabled; 211 } 212 213 214 233 protected void addImpl(Component comp, Object constraints, int index) 234 { 235 if(isRootPaneCheckingEnabled()) { 236 getContentPane().add(comp, constraints, index); 237 } 238 else { 239 super.addImpl(comp, constraints, index); 240 } 241 } 242 243 255 public void remove(Component comp) { 256 if (comp == rootPane) { 257 super.remove(comp); 258 } else { 259 getContentPane().remove(comp); 260 } 261 } 262 263 264 275 public void setLayout(LayoutManager manager) { 276 if(isRootPaneCheckingEnabled()) { 277 getContentPane().setLayout(manager); 278 } 279 else { 280 super.setLayout(manager); 281 } 282 } 283 284 285 291 public JRootPane getRootPane() { 292 return rootPane; 293 } 294 295 296 306 protected void setRootPane(JRootPane root) { 307 if(rootPane != null) { 308 remove(rootPane); 309 } 310 rootPane = root; 311 if(rootPane != null) { 312 boolean checkingEnabled = isRootPaneCheckingEnabled(); 313 try { 314 setRootPaneCheckingEnabled(false); 315 add(rootPane, BorderLayout.CENTER); 316 } 317 finally { 318 setRootPaneCheckingEnabled(checkingEnabled); 319 } 320 } 321 } 322 323 324 330 public Container getContentPane() { 331 return getRootPane().getContentPane(); 332 } 333 334 348 public void setContentPane(Container contentPane) { 349 getRootPane().setContentPane(contentPane); 350 } 351 352 360 public JLayeredPane getLayeredPane() { 361 return getRootPane().getLayeredPane(); 362 } 363 364 375 public void setLayeredPane(JLayeredPane layeredPane) { 376 getRootPane().setLayeredPane(layeredPane); 377 } 378 379 385 public Component getGlassPane() { 386 return getRootPane().getGlassPane(); 387 } 388 389 401 public void setGlassPane(Component glassPane) { 402 getRootPane().setGlassPane(glassPane); 403 } 404 405 414 protected String paramString() { 415 String rootPaneString = (rootPane != null ? 416 rootPane.toString() : ""); 417 String rootPaneCheckingEnabledString = (rootPaneCheckingEnabled ? 418 "true" : "false"); 419 420 return super.paramString() + 421 ",rootPane=" + rootPaneString + 422 ",rootPaneCheckingEnabled=" + rootPaneCheckingEnabledString; 423 } 424 425 426 427 431 protected AccessibleContext accessibleContext = null; 432 433 442 public AccessibleContext getAccessibleContext() { 443 if (accessibleContext == null) { 444 accessibleContext = new AccessibleJApplet(); 445 } 446 return accessibleContext; 447 } 448 449 453 protected class AccessibleJApplet extends AccessibleApplet { 454 } 456 } 457 458 | Popular Tags |