Toolkit

Overview | Package | Class | Use | Tree | Deprecated | Index | Help

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## java.awt
Class Toolkit

    java.lang.Object
      java.awt.Toolkit

    public abstract class Toolkit

extends Object

This class is the abstract superclass of all actual implementations of the Abstract Window Toolkit. Subclasses of `Toolkit` are used to bind the various components to particular native toolkit implementations.

Most applications should not call any of the methods in this class directly. Some methods defined by `Toolkit` query the native operating system directly.

Since:
  JDK1.0
Version:
  1.189, 01/23/03
Author:
  Sami Shaio, Arthur van Hoff, Fred Ecks

Constructor Summary
`Toolkit()`

Method Summary
`void` | `addAWTEventListener(AWTEventListener listener, long eventMask)` Adds an AWTEventListener to receive all AWTEvents dispatched system-wide that conform to the given `eventMask`.
`abstract void` | `beep()` Emits an audio beep.
`abstract int` | `checkImage(Image image, int width, int height, ImageObserver observer)` Indicates the construction status of a specified image that is being prepared for display.
`Image` | `createImage(byte[] imagedata)` Creates an image which decodes the image stored in the specified byte array.
`abstract Image` | `createImage(byte[] imagedata, int imageoffset, int imagelength)` Creates an image which decodes the image stored in the specified byte array, and at the specified offset and length.
`abstract Image` | `createImage(ImageProducer producer)` Creates an image with the specified image producer.
`abstract Image` | `createImage(String filename)` Returns an image which gets pixel data from the specified file.
`abstract Image` | `createImage(URL url)` Returns an image which gets pixel data from the specified URL.
`AWTEventListener[]` | `getAWTEventListeners()` Returns an array of all the `AWTEventListener`s registered on this toolkit.
`AWTEventListener[]` | `getAWTEventListeners(long eventMask)` Returns an array of all the `AWTEventListener`s registered on this toolkit which listen to all of the event types indicates in the `eventMask` argument.
`abstract ColorModel` | `getColorModel()` Determines the color model of this toolkit's screen.
`static Toolkit` | `getDefaultToolkit()` Gets the default toolkit.
`abstract String[]` | `getFontList()` Deprecated. see `GraphicsEnvironment.getAvailableFontFamilyNames()`
`abstract FontMetrics` | `getFontMetrics(Font font)` Deprecated. Deprecated. This returns integer metrics for the default screen.
`abstract Image` | `getImage(String filename)` Returns an image which gets pixel data from the specified file, whose format can be either GIF, JPEG or PNG.
`abstract Image` | `getImage(URL url)` Returns an image which gets pixel data from the specified URL.
`static String` | `getProperty(String key, String defaultValue)` Gets a property with the specified key and default.
`Insets` | `getScreenInsets(GraphicsConfiguration gc)` Gets the insets of the screen.
`abstract int` | `getScreenResolution()` Returns the screen resolution in dots-per-inch.
`abstract Dimension` | `getScreenSize()` Gets the size of the screen.
`EventQueue` | `getSystemEventQueue()` Get the application's or applet's EventQueue instance.
`boolean` | `isFrameStateSupported(int state)` Returns whether Toolkit supports this state for `Frame`s.
`abstract boolean` | `prepareImage(Image image, int width, int height, ImageObserver observer)` Prepares an image for rendering.
`void` | `removeAWTEventListener(AWTEventListener listener)` Removes an AWTEventListener from receiving dispatched AWTEvents.
`abstract void` | `sync()` Synchronizes this toolkit's graphics state.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### Toolkit

    public Toolkit()

Method Detail

### getScreenSize

    public abstract Dimension getScreenSize()
                                     throws HeadlessException

  Gets the size of the screen. On systems with multiple displays, the primary display is used. Multi-screen aware display dimensions are available from `GraphicsConfiguration` and `GraphicsDevice`.

  Returns:
    the size of this toolkit's screen, in pixels.
  Throws:
    `HeadlessException` - if GraphicsEnvironment.isHeadless() returns true
  See Also:
    `GraphicsConfiguration.getBounds()`, `GraphicsEnvironment.isHeadless()`

### getScreenResolution

    public abstract int getScreenResolution()
                                     throws HeadlessException

  Returns the screen resolution in dots-per-inch.

  Returns:
    this toolkit's screen resolution, in dots-per-inch.
  Throws:
    `HeadlessException` - if GraphicsEnvironment.isHeadless() returns true
  See Also:
    `GraphicsEnvironment.isHeadless()`

### getScreenInsets

    public Insets getScreenInsets(GraphicsConfiguration gc)
                           throws HeadlessException

  Gets the insets of the screen.

  Parameters:
    `gc` - a `GraphicsConfiguration`
  Returns:
    the insets of this toolkit's screen, in pixels.
  Throws:
    `HeadlessException` - if GraphicsEnvironment.isHeadless() returns true
  Since:
    1.4
  See Also:
    `GraphicsEnvironment.isHeadless()`

### getColorModel

    public abstract ColorModel getColorModel()
                                      throws HeadlessException

  Determines the color model of this toolkit's screen.

  `ColorModel` is an abstract class that encapsulates the ability to translate between the pixel values of an image and its red, green, blue, and alpha components.

  This toolkit method is called by the `getColorModel` method of the `Component` class.

  Returns:
    the color model of this toolkit's screen.
  Throws:
    `HeadlessException` - if GraphicsEnvironment.isHeadless() returns true
  See Also:
    `GraphicsEnvironment.isHeadless()`, `ColorModel`, `Component.getColorModel()`

### getFontList

    public abstract String[] getFontList()

  Deprecated. see `GraphicsEnvironment.getAvailableFontFamilyNames()`

  Returns the names of the available fonts in this toolkit.

  For 1.1, the following font names are deprecated (the replacement name follows):

  - TimesRoman (use Serif)
  - Helvetica (use SansSerif)
  - Courier (use Monospaced)

  The ZapfDingbats fontname is also deprecated in 1.1 but the characters are defined in Unicode starting at 0x2700, and as of 1.1 Java supports those characters.

  Returns:
    the names of the available fonts in this toolkit.
  See Also:
    `GraphicsEnvironment.getAvailableFontFamilyNames()`

### getFontMetrics

    public abstract FontMetrics getFontMetrics(Font font)

  Deprecated. Deprecated. This returns integer metrics for the default screen.

  Gets the screen device metrics for rendering of the font.

  Parameters:
    `font` - a font
  Returns:
    the screen metrics of the specified font in this toolkit
  See Also:
    `GraphicsEnvironment.getScreenDevices()`

### sync

    public abstract void sync()

  Synchronizes this toolkit's graphics state. Some window systems may do buffering of graphics events.

  This method ensures that the display is up-to-date. It is useful for animation.

### getDefaultToolkit

    public static Toolkit getDefaultToolkit()

  Gets the default toolkit.

  If there is a system property named `"awt.toolkit"`, that property is treated as the name of a class that is a subclass of `Toolkit`.

  If the system property does not exist, then the default toolkit used is the class named `"sun.awt.motif.MToolkit"`, which is a motif implementation of the Abstract Window Toolkit.

  Also loads additional classes into the VM, using the property 'assistive_technologies' specified in the Sun reference implementation by a line in the 'accessibility.properties' file. The form is "assistive_technologies=..." where the "..." is a comma-separated list of assistive technology classes to load. Each class is loaded in the order given and a single instance of each is created using Class.forName(class).newInstance(). This is done just after the AWT toolkit is created. All errors are handled via an AWTError exception.

  Returns:
    the default toolkit.
  Throws:
    `AWTError` - if a toolkit could not be found, or if one could not be accessed or instantiated.

### getImage

    public abstract Image getImage(String filename)

  Returns an image which gets pixel data from the specified file, whose format can be either GIF, JPEG or PNG. The underlying toolkit attempts to resolve multiple requests with the same filename to the same returned Image. Since the mechanism required to facilitate this sharing of Image objects may continue to hold onto images that are no longer of use for an indefinite period of time, developers are encouraged to implement their own caching of images by using the createImage variant wherever available.

  Parameters:
    `filename` - the name of a file containing pixel data in a recognized file format.
  Returns:
    an image which gets its pixel data from the specified file.
  Throws:
    `SecurityException` - if a security manager exists and its `checkRead` method denies read access to the filename.
  See Also:
    `createImage(java.lang.String)`, `SecurityManager.checkRead(java.lang.String)`

### getImage

    public abstract Image getImage(URL url)

  Returns an image which gets pixel data from the specified URL. The pixel data referenced by the specified URL must be in one of the following formats: GIF, JPEG or PNG. The underlying toolkit attempts to resolve multiple requests with the same URL to the same returned Image. Since the mechanism required to facilitate this sharing of Image objects may continue to hold onto images that are no longer of use for an indefinite period of time, developers are encouraged to implement their own caching of images by using the createImage variant wherever available.

  This method will throw `SecurityException` if the caller does not have the permission obtained from `url.openConnection.getPermission()`. For compatibility with pre-1.2 security managers, if the permission is a `FilePermission` or a `SocketPermission`, then the 1.1-style `SecurityManager.checkXXX` methods are called instead of `SecurityManager.checkPermission(java.security.Permission)`.

  Parameters:
    `url` - the URL to use in fetching the pixel data.
  Returns:
    an image which gets its pixel data from the specified URL.
  Throws:
    `SecurityException` - If the caller does not have permission to access this URL.
  See Also:
    `createImage(java.net.URL)`

### createImage

    public abstract Image createImage(String filename)

  Returns an image which gets pixel data from the specified file. The returned Image is a new object which will not be shared with any other caller of this method or its getImage variant.

  Parameters:
    `filename` - the name of a file containing pixel data in a recognized file format.
  Returns:
    an image which gets its pixel data from the specified file.
  Throws:
    `SecurityException` - if a security manager exists and its `checkRead` method denies read access to the filename.
  See Also:
    `getImage(java.lang.String)`, `SecurityManager.checkRead(java.lang.String)`

### createImage

    public abstract Image createImage(URL url)

  Returns an image which gets pixel data from the specified URL. The returned Image is a new object which will not be shared with any other caller of this method or its getImage variant.

  This method will throw `SecurityException` if the caller does not have the permission obtained from `url.openConnection.getPermission()`. For compatibility with pre-1.2 security managers, if the permission is a `FilePermission` or a `SocketPermission`, then the 1.1-style `SecurityManager.checkXXX` methods are called instead of `SecurityManager.checkPermission(java.security.Permission)`.

  Parameters:
    `url` - the URL to use in fetching the pixel data.
  Returns:
    an image which gets its pixel data from the specified URL.
  Throws:
    `SecurityException` - If the caller does not have permission to access this URL.
  See Also:
    `getImage(java.net.URL)`

### prepareImage

    public abstract boolean prepareImage(Image image,
                                         int width,
                                         int height,
                                         ImageObserver observer)

  Prepares an image for rendering.

  If the values of the width and height arguments are both `-1`, this method prepares the image for rendering on the default screen; otherwise, this method prepares an image for rendering on the default screen at the specified width and height.

  The image data is downloaded asynchronously in another thread, and an appropriately scaled screen representation of the image is generated.

  This method is called by components `prepareImage` methods.

  Information on the flags returned by this method can be found with the definition of the `ImageObserver` interface.

  Parameters:
    `image` - the image for which to prepare a screen representation.
    `width` - the width of the desired screen representation, or `-1`.
    `height` - the height of the desired screen representation, or `-1`.
    `observer` - the `ImageObserver` object to be notified as the image is being prepared.
  Returns:
    `true` if the image has already been fully prepared; `false` otherwise.
  See Also:
    `Component.prepareImage(java.awt.Image, java.awt.image.ImageObserver)`, `Component.prepareImage(java.awt.Image, int, int, java.awt.image.ImageObserver)`, `ImageObserver`

### checkImage

    public abstract int checkImage(Image image,
                                   int width,
                                   int height,
                                   ImageObserver observer)

  Indicates the construction status of a specified image that is being prepared for display.

  If the values of the width and height arguments are both `-1`, this method returns the construction status of a screen representation of the specified image in this toolkit. Otherwise, this method returns the construction status of a scaled representation of the image at the specified width and height.

  This method does not cause the image to begin loading. An application must call `prepareImage` to force the loading of an image.

  This method is called by the component's `checkImage` methods.

  Information on the flags returned by this method can be found with the definition of the `ImageObserver` interface.

  Parameters:
    `image` - the image whose status is being checked.
    `width` - the width of the scaled version whose status is being checked, or `-1`.
    `height` - the height of the scaled version whose status is being checked, or `-1`.
    `observer` - the `ImageObserver` object to be notified as the image is being prepared.
  Returns:
    the bitwise inclusive OR of the `ImageObserver` flags for the image data that is currently available.
  See Also:
    `prepareImage(java.awt.Image, int, int, java.awt.image.ImageObserver)`, `Component.checkImage(java.awt.Image, java.awt.image.ImageObserver)`, `Component.checkImage(java.awt.Image, int, int, java.awt.image.ImageObserver)`, `ImageObserver`

### createImage

    public abstract Image createImage(ImageProducer producer)

  Creates an image with the specified image producer.

  Parameters:
    `producer` - the image producer to be used.
  Returns:
    an image with the specified image producer.
  See Also:
    `Image`, `ImageProducer`, `Component.createImage(java.awt.image.ImageProducer)`

### createImage

    public Image createImage(byte[] imagedata)

  Creates an image which decodes the image stored in the specified byte array.

  The data must be in some image format, such as GIF or JPEG, that is supported by this toolkit.

  Parameters:
    `imagedata` - an array of bytes, representing image data in a supported image format.
  Returns:
    an image.
  Since:
    JDK1.1

### createImage

    public abstract Image createImage(byte[] imagedata,
                                      int imageoffset,
                                      int imagelength)

  Creates an image which decodes the image stored in the specified byte array, and at the specified offset and length. The data must be in some image format, such as GIF or JPEG, that is supported by this toolkit.

  Parameters:
    `imagedata` - an array of bytes, representing image data in a supported image format.
    `imageoffset` - the offset of the beginning of the data in the array.
    `imagelength` - the length of the data in the array.
  Returns:
    an image.
  Since:
    JDK1.1

### beep

    public abstract void beep()

  Emits an audio beep.

  Since:
    JDK1.1

### isFrameStateSupported

    public boolean isFrameStateSupported(int state)
                                  throws HeadlessException

  Returns whether Toolkit supports this state for `Frame`s. This method tells whether the UI concept of, say, iconification is supported.

  Parameters:
    `state` - one of named frame state constants.
  Returns:
    `true` is this frame state is supported by this Toolkit implementation, `false` otherwise.
  Throws:
    `HeadlessException` - if `GraphicsEnvironment.isHeadless()` returns `true`.
  Since:
    1.4

### getProperty

    public static String getProperty(String key,
                                     String defaultValue)

  Gets a property with the specified key and default. This method returns defaultValue if the property is not found.

### getSystemEventQueue

    public final EventQueue getSystemEventQueue()

  Get the application's or applet's EventQueue instance. Depending on the Toolkit implementation, different EventQueues may be returned for different applets. Applets should therefore not assume that the EventQueue instance returned by this method will be shared by other applets or the system.

  First, if there is a security manager, its `checkAwtEventQueueAccess` method is called. If the default implementation of `checkAwtEventQueueAccess` is used (that is, that method is not overriden), then this results in a call to the security manager's `checkPermission` method with an `AWTPermission("accessEventQueue")` permission.

  Returns:
    the `EventQueue` object.
  Throws:
    `SecurityException` - if a security manager exists and its ``SecurityManager.checkAwtEventQueueAccess()`` method denies access to the EventQueue.
  See Also:
    `AWTPermission`

### addAWTEventListener

    public void addAWTEventListener(AWTEventListener listener,
                                    long eventMask)

  Adds an AWTEventListener to receive all AWTEvents dispatched system-wide that conform to the given `eventMask`.

  First, if there is a security manager, its `checkPermission` method is called with an `AWTPermission("listenToAllAWTEvents")` permission. This may result in a SecurityException.

  `eventMask` is a bitmask of event types to receive. It is constructed by bitwise OR-ing together the event masks defined in `AWTEvent`.

  Note: event listener use is not recommended for normal application use, but are intended solely to support special purpose facilities including support for accessibility, event record/playback, and diagnostic tracing. If listener is null, no exception is thrown and no action is performed.

  Parameters:
    `listener` - the event listener.
    `eventMask` - the bitmask of event types to receive
  Throws:
    `SecurityException` - if a security manager exists and its `checkPermission` method doesn't allow the operation.
  Since:
    1.2
  See Also:
    `removeAWTEventListener(java.awt.event.AWTEventListener)`, `SecurityManager.checkPermission(java.security.Permission)`, `AWTEvent`, `AWTPermission`, `AWTEventListener`, `AWTEventListenerProxy`

### removeAWTEventListener

    public void removeAWTEventListener(AWTEventListener listener)

  Removes an AWTEventListener from receiving dispatched AWTEvents.

  First, if there is a security manager, its `checkPermission` method is called with an `AWTPermission("listenToAllAWTEvents")` permission. This may result in a SecurityException.

  Note: event listener use is not recommended for normal application use, but are intended solely to support special purpose facilities including support for accessibility, event record/playback, and diagnostic tracing. If listener is null, no exception is thrown and no action is performed.

  Parameters:
    `listener` - the event listener.
  Throws:
    `SecurityException` - if a security manager exists and its `checkPermission` method doesn't allow the operation.
  Since:
    1.2
  See Also:
    `addAWTEventListener(java.awt.event.AWTEventListener, long)`, `SecurityManager.checkPermission(java.security.Permission)`, `AWTEvent`, `AWTPermission`, `AWTEventListener`, `AWTEventListenerProxy`

### getAWTEventListeners

    public AWTEventListener[] getAWTEventListeners()

  Returns an array of all the `AWTEventListener`s registered on this toolkit.

  First, if there is a security manager, its `checkPermission` method is called with an `AWTPermission("listenToAllAWTEvents")` permission. This may result in a SecurityException.

  Listeners can be returned within `AWTEventListenerProxy` objects, which also contain the event mask for the given listener. Note that listener objects added multiple times appear only once in the returned array.

  Returns:
    all of the `AWTEventListener`s or an empty array if no listeners are currently registered
  Throws:
    `SecurityException` - if a security manager exists and its `checkPermission` method doesn't allow the operation.
  Since:
    1.4
  See Also:
    `addAWTEventListener(java.awt.event.AWTEventListener, long)`, `removeAWTEventListener(java.awt.event.AWTEventListener)`, `SecurityManager.checkPermission(java.security.Permission)`, `AWTEvent`, `AWTPermission`, `AWTEventListener`, `AWTEventListenerProxy`

### getAWTEventListeners

    public AWTEventListener[] getAWTEventListeners(long eventMask)

  Returns an array of all the `AWTEventListener`s registered on this toolkit which listen to all of the event types indicates in the `eventMask` argument.

  First, if there is a security manager, its `checkPermission` method is called with an `AWTPermission("listenToAllAWTEvents")` permission. This may result in a SecurityException.

  Listeners can be returned within `AWTEventListenerProxy` objects, which also contain the event mask for the given listener. Note that listener objects added multiple times appear only once in the returned array.

  Parameters:
    `eventMask` - the bitmask of event types to listen for
  Returns:
    all of the `AWTEventListener`s registered on this toolkit for the specified event types, or an empty array if no such listeners are currently registered
  Throws:
    `SecurityException` - if a security manager exists and its `checkPermission` method doesn't allow the operation.
  Since:
    1.4
  See Also:
    `addAWTEventListener(java.awt.event.AWTEventListener, long)`, `removeAWTEventListener(java.awt.event.AWTEventListener)`, `SecurityManager.checkPermission(java.security.Permission)`, `AWTEvent`, `AWTPermission`, `AWTEventListener`, `AWTEventListenerProxy`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD