Java Awt Toolkit

JavaAwtToolkit demonstrates a few JavaPatterns.

The java.awt.Toolkit is the glue that joins the platform-independent classes in the java.awt package with their counterparts in java.awt.peer. Some methods defined by Toolkit query the native operating system directly.

java.awt.Toolkit is an AbstractFactory. Created through the SingletonPattern using the ParameterClasses JavaIdiom.

 public abstract class  Toolkit {

// Our singleton instance. private static Toolkit toolkit;

public static synchronized Toolkit getDefaultToolkit() { if (toolkit == null) { try { java.lang.Compiler.disable();

java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() { public Object run() { String nm = null; try { // The ParameterClasses implementation. nm = System.getProperty("awt.toolkit", "sun.awt.motif.MToolkit"); toolkit = (Toolkit)Class.forName(nm).newInstance(); } catch (ClassNotFoundException e) { throw new AWTError("Toolkit not found: " + nm); } catch (InstantiationException e) { throw new AWTError("Could not instantiate Toolkit: " + nm); } catch (IllegalAccessException e) { throw new AWTError("Could not access Toolkit: " + nm); } return null; } }); loadAssistiveTechnologies(); } finally { // Make sure to always re-enable the JIT. java.lang.Compiler.enable(); } } return toolkit; }

Diagram of AbstractFactory:

Diagram of Toolkit as AbstractFactory:


See also TheStoryOfAwt


CategoryJavaPlatform


EditText of this page (last edited April 29, 2003) or FindPage with title or text search