Toolkit
are used to bind the various components
to particular native toolkit implementations.
Many GUI operations may be performed asynchronously. This means that if you set the state of a component, and then immediately query the state, the returned value may not yet reflect the requested change. This includes, but is not limited to:
ScrollPane.setScrollPosition
and then getScrollPosition
may return an incorrect
value if the original request has not yet been processed.
setVisible(true)
on a Window
,
Frame
or Dialog
may occur
asynchronously.
setSize
, setBounds
or
setLocation
on a Window
,
Frame
or Dialog
are forwarded
to the underlying window management system and may be
ignored or modified. See java.awt.Window
for
more information.
Most applications should not call any of the methods in this
class directly. The methods defined by Toolkit
are
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.
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.
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.
Note that multi-frame images are invalid and may cause this method to hang.
The data must be in some image format, such as GIF or JPEG, that is supported by this toolkit.
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
x
and y
, multiple invocations of
x.equals(y) consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
x
,
x.equals(null)
should return false
.
The equals method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.
AWTEventListener
s
registered on this toolkit. 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.AWTEventListener
s
registered on this toolkit which listen to all of the event
types indicates in the eventMask
argument.
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.Note: if an image is used whose dimensions don't match a supported size (as returned by this method), the Toolkit implementation will attempt to resize the image to a supported size. Since converting low-resolution images is difficult, no guarantees are made as to the quality of a cursor image which isn't a supported size. It is therefore recommended that this method be called and an appropriate image used so no image conversion is made.
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.
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.
For 1.1, the following font names are deprecated (the replacement name follows):
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.
Note: if an image is used which has more colors in its palette than the supported maximum, the Toolkit implementation will attempt to flatten the palette to the maximum. Since converting low-resolution images is difficult, no guarantees are made as to the quality of a cursor image which has more colors than the system supports. It is therefore recommended that this method be called and an appropriate image used so no image conversion is made.
Menu shortcuts, which are embodied in the
MenuShortcut
class, are handled by the
MenuBar
class.
By default, this method returns Event.CTRL_MASK
.
Toolkit implementations should override this method if the
Control key isn't the correct key for accelerators.
PrintJob
object which is the result of initiating
a print operation on the toolkit's platform.
Each actual implementation of this method should first check if there
is a security manager installed. If there is, the method should call
the security manager's checkPrintJobAccess
method to
ensure initiation of a print operation is allowed. If the default
implementation of checkPrintJobAccess
is used (that is,
that method is not overriden), then this results in a call to the
security manager's checkPermission
method with a
RuntimePermission("queuePrintJob")
permission.
PrintJob
object which is the result of initiating
a print operation on the toolkit's platform.
Each actual implementation of this method should first check if there
is a security manager installed. If there is, the method should call
the security manager's checkPrintJobAccess
method to
ensure initiation of a print operation is allowed. If the default
implementation of checkPrintJobAccess
is used (that is,
that method is not overriden), then this results in a call to the
security manager's checkPermission
method with a
RuntimePermission("queuePrintJob")
permission.
PropertyChangeListener
s
associated with the named property.GraphicsConfiguration
and
GraphicsDevice
.
In addition to any and all formats specified in the flavormap.properties
file, or other file specified by the AWT.DnD.flavorMapFileURL
Toolkit property, text returned by the system Clipboard's
getTransferData()
method is available in the following flavors:
java.awt.datatransfer.StringSelection
, if the
requested flavor is DataFlavor.plainTextFlavor
, or an
equivalent flavor, a Reader is returned. Note: The behavior of
the system Clipboard's getTransferData()
method for
DataFlavor.plainTextFlavor
, and equivalent DataFlavors, is
inconsistent with the definition of DataFlavor.plainTextFlavor
. Because of this, support for
DataFlavor.plainTextFlavor
, and equivalent flavors, is
deprecated.
Each actual implementation of this method should first check if there
is a security manager installed. If there is, the method should call
the security manager's checkSystemClipboardAccess
method
to ensure it's ok to to access the system clipboard. If the default
implementation of checkSystemClipboardAccess
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("accessClipboard")
permission.
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.
Clipboard
object. This allows an application to read and
modify the current, system-wide selection.
An application is responsible for updating the system selection whenever
the user selects text, using either the mouse or the keyboard.
Typically, this is implemented by installing a
FocusListener
on all Component
s which support
text selection, and, between FOCUS_GAINED
and
FOCUS_LOST
events delivered to that Component
,
updating the system selection Clipboard
when the selection
changes inside the Component
. Properly updating the system
selection ensures that a Java application will interact correctly with
native applications and other Java applications running simultaneously
on the system. Note that java.awt.TextComponent
and
javax.swing.text.JTextComponent
already adhere to this
policy. When using these classes, and their subclasses, developers need
not write any additional code.
Some platforms do not support a system selection Clipboard
.
On those platforms, this method will return null
. In such a
case, an application is absolved from its responsibility to update the
system selection Clipboard
as described above.
Each actual implementation of this method should first check if there
is a SecurityManager
installed. If there is, the method
should call the SecurityManager
's
checkSystemClipboardAccess
method to ensure that client
code has access the system selection. If the default implementation of
checkSystemClipboardAccess
is used (that is, if the method
is not overridden), then this results in a call to the
SecurityManager
's checkPermission
method with
an AWTPermission("accessClipboard")
permission.
java.util.Hashtable
.
The general contract of hashCode
is:
hashCode
method on each of
the two objects must produce the same integer result.
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)
Frame
s. This method tells whether the UI
concept of, say, maximization or iconification is
supported. It will always return false for "compound" states
like Frame.ICONIFIED|Frame.MAXIMIZED_VERT
.
In other words, the rule of thumb is that only queries with a
single frame state constant as an argument are meaningful.wait
methods.
The awakened thread will not be able to proceed until the current thread relinquishes the lock on this object. The awakened thread will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened thread enjoys no reliable privilege or disadvantage in being the next thread to lock this object.
This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways:
synchronized
statement
that synchronizes on the object.
Class,
by executing a
synchronized static method of that class.
Only one thread at a time can own an object's monitor.
wait
methods.
The awakened threads will not be able to proceed until the current thread relinquishes the lock on this object. The awakened threads will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened threads enjoy no reliable privilege or disadvantage in being the next thread to lock this object.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
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.
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.
Depending on the platform, setting the state of a locking key may involve event processing and therefore may not be immediately observable through getLockingKeyState.
This method ensures that the display is up-to-date. It is useful for animation.
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
The current thread must own this object's monitor. The thread
releases ownership of this monitor and waits until another thread
notifies threads waiting on this object's monitor to wake up
either through a call to the notify
method or the
notifyAll
method. The thread then waits until it can
re-obtain ownership of the monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) { while (<condition does not hold>) obj.wait(); ... // Perform action appropriate to condition }This method should only be called by a thread that is the owner of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.The current thread must own this object's monitor.
This method causes the current thread (call it T) to place itself in the wait set for this object and then to relinquish any and all synchronization claims on this object. Thread T becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:
A thread can also wake up without being notified, interrupted, or timing out, a so-called spurious wakeup. While this will rarely occur in practice, applications must guard against it by testing for the condition that should have caused the thread to be awakened, and continuing to wait if the condition is not satisfied. In other words, waits should always occur in loops, like this one:
synchronized (obj) { while (<condition does not hold>) obj.wait(timeout); ... // Perform action appropriate to condition }(For more information on this topic, see Section 3.2.3 in Doug Lea's "Concurrent Programming in Java (Second Edition)" (Addison-Wesley, 2000), or Item 50 in Joshua Bloch's "Effective Java Programming Language Guide" (Addison-Wesley, 2001).
If the current thread is interrupted by another thread while it is waiting, then an InterruptedException is thrown. This exception is not thrown until the lock status of this object has been restored as described above.
Note that the wait method, as it places the current thread into the wait set for this object, unlocks only this object; any other objects on which the current thread may be synchronized remain locked while the thread waits.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
This method is similar to the wait
method of one
argument, but it allows finer control over the amount of time to
wait for a notification before giving up. The amount of real time,
measured in nanoseconds, is given by:
1000000*timeout+nanos
In all other respects, this method does the same thing as the method of one argument. In particular, wait(0, 0) means the same thing as wait(0).
The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until either of the following two conditions has occurred:
notify
method
or the notifyAll
method.
timeout
milliseconds plus nanos
nanoseconds arguments, has
elapsed.
The thread then waits until it can re-obtain ownership of the monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) { while (<condition does not hold>) obj.wait(timeout, nanos); ... // Perform action appropriate to condition }This method should only be called by a thread that is the owner of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.