java.applet.Applet
that adds support for
the JFC/Swing component architecture.
You can find task-oriented documentation about using JApplet
in The Java Tutorial,
in the section
How to Make Applets.
The JApplet
class is slightly incompatible with
java.applet.Applet
. JApplet
contains a
JRootPane
as its only child. The contentPane
should be the parent of any children of the JApplet
.
As a convenience add
and its variants, remove
and
setLayout
have been overridden to forward to the
contentPane
as necessary. This means you can write:
applet.add(child);And the child will be added to the
contentPane
.
The contentPane
will always be non-null
.
Attempting to set it to null
will cause the
JApplet
to throw an exception. The default
contentPane
will have a BorderLayout
manager set on it.
Refer to javax.swing.RootPaneContainer
for details on adding, removing and setting the LayoutManager
of a JApplet
.
Please see the JRootPane
documentation for a
complete description of the contentPane
, glassPane
,
and layeredPane
properties.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans
package.
Please see java.beans.XMLEncoder
.
This constructor sets the component's locale property to the value
returned by JComponent.getDefaultLocale
.
getAlignmentY
.
Specifies an alignment to the bottom of the component.getAlignmentY
and
getAlignmentX
. Specifies an alignment to
the center of the componentgetAlignmentX
.
Specifies an alignment to the left side of the component.getAlignmentX
.
Specifies an alignment to the right side of the component.getAlignmentY()
.
Specifies an alignment to the top of the component.
Note: If a component has been added to a container that
has been displayed, validate
must be
called on that container to display the new component.
If multiple components are being added, you can improve
efficiency by calling validate
only once,
after all the components have been added.
Note: If a component has been added to a container that
has been displayed, validate
must be
called on that container to display the new component.
If multiple components are being added, you can improve
efficiency by calling validate
only once,
after all the components have been added.
Note: If a component has been added to a container that
has been displayed, validate
must be
called on that container to display the new component.
If multiple components are being added, you can improve
efficiency by calling validate
only once,
after all the components have been added.
Note: If a component has been added to a container that
has been displayed, validate
must be
called on that container to display the new component.
If multiple components are being added, you can improve
efficiency by calling validate
only once,
after all the components have been added.
This method is obsolete as of 1.1. Please use the
method add(Component, Object)
instead.
l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.getInputMethodRequests
to return an
InputMethodRequests
instance.
If listener l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.For information on how mouse wheel events are dispatched, see the class description for MouseWheelEvent .
If l is null
, no exception is thrown and no
action is performed.
If listener is null, no exception is thrown and no action is performed.
If listener is null, no exception is thrown and no action is performed.
ComponentOrientation
property of this container
and all components contained within it.false
, this Container is inheriting the
Set from an ancestor, or from the current KeyboardFocusManager.
This method does not cause the image to begin loading. An
application must use the prepareImage
method
to force the loading of an image.
Information on the flags returned by this method can be found
with the discussion of the ImageObserver
interface.
This method does not cause the image to begin loading. An
application must use the prepareImage
method
to force the loading of an image.
The checkImage
method of Component
calls its peer's checkImage
method to calculate
the flags. If this component does not yet have a peer, the
component's toolkit's checkImage
method is called
instead.
Information on the flags returned by this method can be found
with the discussion of the ImageObserver
interface.
x
and y
are defined to be
relative to the coordinate system of this component.VolatileImage
interface.stop
method
will always be called before destroy
.
A subclass of Applet
should override this method if
it has any operation that it wants to perform before it is
destroyed. For example, an applet with threads would use the
init
method to create the threads and the
destroy
method to kill them.
The implementation of this method provided by the
Applet
class does nothing.
processEvent
before returning for 1.1-style
events which have been enabled for the Component
.validate
method instead.
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.
The findComponentAt method is different from getComponentAt in that getComponentAt only searches the Container's immediate children; if the containing component is a Container, findComponentAt will search that child to find a nested component.
The findComponentAt method is different from getComponentAt in that getComponentAt only searches the Container's immediate children; if the containing component is a Container, findComponentAt will search that child to find a nested component.
This environment of an applet represents the document that contains the applet.
String
containing information
about the author, version, and copyright of the applet.
The implementation of this method provided by the
Applet
class returns null
.
AudioClip
object specified by the
URL
argument.
This method always returns immediately, whether or not the audio clip exists. When this applet attempts to play the audio clip, the data will be loaded.
AudioClip
object specified by the
URL
and name
arguments.
This method always returns immediately, whether or not the audio clip exists. When this applet attempts to play the audio clip, the data will be loaded.
Rectangle
object. The bounds specify this
component's width, height, and location relative to
its parent.null
a new
Rectangle
is allocated.
This version of getBounds
is useful if the caller
wants to avoid allocating a new Rectangle
object
on the heap.ColorModel
used to display
the component on the output device.LayoutManager
and Component
subclasses that wish to respect orientation should call this method to
get the component's orientation before performing layout or drawing.Cursor.DEFAULT_CURSOR
is returned.The document base is:http://java.sun.com/products/jdk/1.2/index.html
http://java.sun.com/products/jdk/1.2/index.html
DropTarget
associated with this
Component
.setFocusTraversalKeys
for a full description of each key.)
If a Set of traversal keys has not been explicitly defined for this Container, then this Container's parent's Set is returned. If no Set has been explicitly defined for any of this Container's ancestors, then the current KeyboardFocusManager's default Set is returned.
null
if this component is currently not
displayable.GraphicsConfiguration
associated with this
Component
.
If the Component
has not been assigned a specific
GraphicsConfiguration
,
the GraphicsConfiguration
of the
Component
object's top-level container is
returned.
If the Component
has been created, but not yet added
to a Container
, this method returns null
.component.getBounds().heightcomponent.getSize().height
because it
doesn't cause any heap allocations.Image
object that can then be painted on
the screen. The url
that is passed as an argument
must specify an absolute URL.
This method always returns immediately, whether or not the image exists. When this applet attempts to draw the image on the screen, the data will be loaded. The graphics primitives that draw the image will incrementally paint on the screen.
Image
object that can then be painted on
the screen. The url
argument must specify an absolute
URL. The name
argument is a specifier that is
relative to the url
argument.
This method always returns immediately, whether or not the image exists. When this applet attempts to draw the image on the screen, the data will be loaded. The graphics primitives that draw the image will incrementally paint on the screen.
InputMethodRequests
instance.
At the same time, it also has to handle input method events.
A Frame
object, for example, has a top inset that
corresponds to the height of the frame's title bar.
FooListener
s
upon this Container
.
FooListener
s are registered using the
addFooListener
method.
You can specify the listenerType
argument
with a class literal, such as
FooListener.class
.
For example, you can query a
Container
c
for its container listeners with the following code:
ContainerListener[] cls = (ContainerListener[])(c.getListeners(ContainerListener.class));If no such listeners exist, this method returns an empty array.
Due to the asynchronous nature of native event handling, this
method can return outdated values (for instance, after several calls
of setLocation()
in rapid succession). For this
reason, the recommended method of obtaining a component's position is
within java.awt.event.ComponentListener.componentMoved()
,
which is called after the operating system has finished moving the
component.
null
a new
Point
is allocated.
This version of getLocation
is useful if the
caller wants to avoid allocating a new Point
object on the heap.Component
's
coordinate space if the Component
is directly under the mouse
pointer, otherwise returns null
.
If the Component
is not showing on the screen, this method
returns null
even if the mouse pointer is above the area
where the Component
would be displayed.
If the Component
is partially or fully obscured by other
Component
s or native windows, this method returns a non-null
value only if the mouse pointer is located above the unobscured part of the
Component
.
For Container
s it returns a non-null value if the mouse is
above the Container
itself or above any of its descendants.
Use
if you need to exclude children.
Sometimes the exact mouse coordinates are not important, and the only thing
that matters is whether a specific Component
is under the mouse
pointer. If the return value of this method is null
, mouse
pointer is not directly above the Component
.
Container
's
coordinate space if the Container
is under the mouse pointer,
otherwise returns null
.
This method is similar to
with the exception
that it can take the Container
's children into account.
If allowChildren
is false
, this method will return
a non-null value only if the mouse pointer is above the Container
directly, not above the part obscured by children.
If allowChildren
is true
, this method returns
a non-null value if the mouse pointer is above Container
or any
of its descendants.<applet code="Clock" width=50 height=50> <param name=Color value="blue"> </applet>
then a call to getParameter("Color")
returns the
value "blue"
.
The name
argument is case insensitive.
Strings
describing these parameters.
Each element of the array should be a set of three
Strings
containing the name, the type, and a
description. For example:
String pinfo[][] = { {"fps", "1-10", "frames per second"}, {"repeat", "boolean", "repeat image loop"}, {"imgs", "url", "images directory"} };
The implementation of this method provided by the
Applet
class returns null
.
Dimension
object. The height
field of the Dimension
object contains
this component's height, and the width
field of the Dimension
object contains
this component's width.null
a new
Dimension
object is allocated. This version of
getSize
is useful if the caller wants to avoid
allocating a new Dimension
object on the heap.component.getBounds().width
,
or component.getSize().width
because it
doesn't cause any heap allocations.component.getBounds().x
,
or component.getLocation().x
because it doesn't
cause any heap allocations.component.getBounds().y
,
or component.getLocation().y
because it
doesn't cause any heap allocations.true
if this Component
is the
focus owner. This method is obsolete, and has been replaced by
isFocusOwner()
.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.)
imageUpdate
method of an ImageObserver
is called when more information about an
image which had been previously requested using an asynchronous
routine such as the drawImage
method of
Graphics
becomes available.
See the definition of imageUpdate
for
more information on this method and its arguments.
The imageUpdate
method of Component
incrementally draws an image on the component as more of the bits
of the image are available.
If the system property awt.image.incrementaldraw
is missing or has the value true
, the image is
incrementally drawn. If the system property has any other value,
then the image is not drawn until it has been completely loaded.
Also, if incremental drawing is in effect, the value of the
system property awt.image.redrawrate
is interpreted
as an integer to give the maximum redraw rate, in milliseconds. If
the system property is missing or cannot be interpreted as an
integer, the redraw rate is once every 100ms.
The interpretation of the x
, y
,
width
, and height
arguments depends on
the value of the infoflags
argument.
start
method is
called.
A subclass of Applet
should override this method if
it has initialization to perform. For example, an applet with
threads would use the init
method to create the
threads and the destroy
method to kill them.
The implementation of this method provided by the
Applet
class does nothing.
start
method is called. It becomes
inactive just before its stop
method is called.false
, this Component is
inheriting its background color from an ancestor.false
, this Component is inheriting
its cursor from an ancestor.A component is made displayable either when it is added to a displayable containment hierarchy or when its containment hierarchy is made displayable. A containment hierarchy is made displayable when its ancestor window is either packed or made visible.
A component is made undisplayable either when it is removed from a displayable containment hierarchy or when its containment hierarchy is made undisplayable. A containment hierarchy is made undisplayable when its ancestor window is disposed.
setEnabled
method.true
for both such
Containers in this case.true
if this Component
is the
focus owner.Component
can become the focus
owner.true
then when
keyboard focus manager searches container hierarchy for focus
traversal policy and encounters this container before any other
container with this property as true or focus cycle roots then
its focus traversal policy will be used instead of focus cycle
root's policy.false
, this
Container will inherit its focus traversal policy from an ancestor.false
, this Component is inheriting its
font from an ancestor.false
, this Component is
inheriting its foreground color from an ancestor.Component
and Container
,
other than the ones defined in this package like Button
or Scrollbar
, are lightweight.
All of the Swing components are lightweights.
This method will always return false
if this component
is not displayable because it is impossible to determine the
weight of an undisplayable component.
null
value otherwise returns false.setMinimumSize
has been
invoked with a non-null value.An opaque component paints every pixel within its rectangular region. A non-opaque component paints only some of its pixels, allowing the pixels underneath it to "show through". A component that does not fully paint its pixels therefore provides a degree of transparency. Only lightweight components can be transparent.
Subclasses that guarantee to always completely paint their contents should override this method and return true. All of the "heavyweight" AWT components are opaque.
null
value otherwise returns false.Frame
objects.System.out
.
The immediate children of the container are printed with
an indentation of indent+1
. The children
of those children are printed at indent+2
and so on.
The immediate children of the container are printed with
an indentation of indent+1
. The children
of those children are printed at indent+2
and so on.
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.
The origin of the graphics context, its
(0
, 0
) coordinate point, is the
top-left corner of this component. The clipping region of the
graphics context is the bounding rectangle of this component.
The image data is downloaded asynchronously in another thread, and an appropriately scaled screen representation of the image is generated.
The origin of the graphics context, its
(0
, 0
) coordinate point, is the
top-left corner of this component. The clipping region of the
graphics context is the bounding rectangle of this component.
comp
is not the rootPane
, this will forward
the call to the contentPane
. This will do nothing if
comp
is not a child of the JFrame
or
contentPane
.index
,
from this container.
This method also notifies the layout manager to remove the
component from this container's layout via the
removeLayoutComponent
method.removeLayoutComponent
method.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.l
is null
,
no exception is thrown and no action is performed.If listener is null, no exception is thrown and no action is performed.
PropertyChangeListener
from the listener
list for a specific property. This method should be used to remove
PropertyChangeListener
s
that were registered for a specific bound property.
If propertyName
or listener
is null
,
no exception is thrown and no action is taken.
If this component is a lightweight component, this method
causes a call to this component's paint
method as soon as possible. Otherwise, this method causes
a call to this component's update
method as soon
as possible.
Note: For more information on the paint mechanisms utilitized by AWT and Swing, including information on how to write the most efficient painting code, see Painting in AWT and Swing.
If this component is a lightweight component, this method
causes a call to this component's paint
method
as soon as possible. Otherwise, this method causes a call to
this component's update
method as soon as possible.
Note: For more information on the paint mechanisms utilitized by AWT and Swing, including information on how to write the most efficient painting code, see Painting in AWT and Swing.
paint
within tm
milliseconds.
Note: For more information on the paint mechanisms utilitized by AWT and Swing, including information on how to write the most efficient painting code, see Painting in AWT and Swing.
tm
milliseconds.
If this component is a lightweight component, this method causes
a call to this component's paint
method.
Otherwise, this method causes a call to this component's
update
method.
Note: For more information on the paint mechanisms utilitized by AWT and Swing, including information on how to write the most efficient painting code, see Painting in AWT and Swing.
This method cannot be used to set the focus owner to no Component at
all. Use KeyboardFocusManager.clearGlobalFocusOwner()
instead.
Because the focus behavior of this method is platform-dependent,
developers are strongly encouraged to use
requestFocusInWindow
when possible.
This method returns a boolean value. If false
is returned,
the request is guaranteed to fail. If true
is
returned, the request will succeed unless it is vetoed, or an
extraordinary event, such as disposal of the Component's peer, occurs
before the request can be granted by the native windowing system. Again,
while a return value of true
indicates that the request is
likely to succeed, developers must never assume that this Component is
the focus owner until this Component receives a FOCUS_GAINED event.
This method cannot be used to set the focus owner to no Component at
all. Use KeyboardFocusManager.clearGlobalFocusOwner()
instead.
The focus behavior of this method can be implemented uniformly across
platforms, and thus developers are strongly encouraged to use this
method over requestFocus
when possible. Code which relies
on requestFocus
may exhibit different focus behavior on
different platforms.
The background color affects each component differently and the parts of the component that are affected by the background color may differ between operating systems.
x
and y
, and the
new size is specified by width
and height
.r
. This component's new
position is specified by r.x
and r.y
,
and its new size is specified by r.width
and
r.height
LayoutManager
and Component
subclasses will use this property to
determine how to lay out and draw components.
At construction time, a component's orientation is set to
ComponentOrientation.UNKNOWN
,
indicating that it has not been specified
explicitly. The UNKNOWN orientation behaves the same as
ComponentOrientation.LEFT_TO_RIGHT
.
To set the orientation of a single component, use this method. To set the orientation of an entire component hierarchy, use applyComponentOrientation .
If the component is a child of some other container, it is
removed from that container before being added to this container.
The important difference between this method and
java.awt.Container.add(Component, int)
is that this method
doesn't call removeNotify
on the component while
removing it from its previous container unless necessary and when
allowed by the underlying native windowing system. This way, if the
component has the keyboard focus, it maintains the focus when
moved to the new position.
This property is guaranteed to apply only to lightweight
non-Container
components.
Note: Not all platforms support changing the z-order of
heavyweight components from one container into another without
the call to removeNotify
. There is no way to detect
whether a platform supports this, so developers shouldn't make
any assumptions.
The contentPane my not be null.
Generally implemented with
getRootPane().setContentPane(contentPane);
contains
method for
this component returns true for the current cursor location, and
this Component is visible, displayable, and enabled. Setting the
cursor of a Container
causes that cursor to be displayed
within all of the container's subcomponents, except for those
that have a non-null
cursor.DropTarget
with this component.
The Component
will receive drops only if it
is enabled.b
. An enabled component can respond to user
input and generate events. Components are enabled initially by default.
Note: Disabling a lightweight component does not prevent it from receiving MouseEvents.
The alternative way to specify the traversal order of this Container's children is to make this Container a focus traversal policy provider.
The default values for a Container's focus traversal keys are implementation-dependent. Sun recommends that all implementations for a particular native platform use the same default values. The recommendations for Windows and Unix are listed below. These recommendations are used in the Sun AWT implementations.
Identifier | Meaning | Default | |
---|---|---|---|
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS | Normal forward keyboard traversal | TAB on KEY_PRESSED, CTRL-TAB on KEY_PRESSED | |
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS | Normal reverse keyboard traversal | SHIFT-TAB on KEY_PRESSED, CTRL-SHIFT-TAB on KEY_PRESSED | |
KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS | Go up one focus traversal cycle | none | |
KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS | Go down one focus traversal cycle | none |
Using the AWTKeyStroke API, client code can specify on which of two specific KeyEvents, KEY_PRESSED or KEY_RELEASED, the focus traversal operation will occur. Regardless of which KeyEvent is specified, however, all KeyEvents related to the focus traversal key, including the associated KEY_TYPED event, will be consumed, and will not be dispatched to any Container. It is a runtime error to specify a KEY_TYPED event as mapping to a focus traversal operation, or to map the same event to multiple default focus traversal operations.
If a value of null is specified for the Set, this Container inherits the Set from its parent. If all ancestors of this Container have null specified for the Set, then the current KeyboardFocusManager's default Set is used.
If this Container is not a focus cycle root, the policy will be remembered, but will not be used or inherited by this or any other Containers until this Container is made a focus cycle root.
true
will be used to acquire focus traversal policy
instead of closest focus cycle root ancestor.The glassPane may not be null.
Generally implemented with
getRootPane().setGlassPane(glassPane);
This is useful, for example, if running under full-screen mode and better performance is desired, or if page-flipping is used as the buffer strategy.
The layeredPane may not be null.
Generally implemented with
getRootPane().setLayeredPane(layeredPane);
LayoutManager
.
Overridden to conditionally forward the call to the
contentPane
.
Refer to javax.swing.RootPaneContainer
for
more information.x
and y
parameters in the coordinate space of this component's parent.p
. Point
p
is given in the parent's coordinate space.getMaximumSize
will always
return this value. Setting the maximum size to null
restores the default behavior.getMinimumSize
will always
return this value. Setting the minimum size to null
restores the default behavior.getPreferredSize
will always
return this value. Setting the preferred size to null
restores the default behavior.d.width
and height d.height
.width
and height height
.If there is a security manager, its checkPermission
method is called with the
AWTPermission("setAppletStub")
permission if a stub has already been set.
b
.init
method and each time the applet is revisited
in a Web page.
A subclass of Applet
should override this method if
it has any operation that it wants to perform each time the Web
page containing it is visited. For example, an applet with
animation might want to use the start
method to
resume animation, and the stop
method to suspend the
animation.
Note: some methods, such as getLocationOnScreen
, can only
provide meaningful results if the applet is showing. Because
isShowing
returns false
when the applet's
start
is first called, methods requiring
isShowing
to return true
should be called from
a ComponentListener
.
The implementation of this method provided by the
Applet
class does nothing.
A subclass of Applet
should override this method if
it has any operation that it wants to perform each time the Web
page containing it is no longer visible. For example, an applet
with animation might want to use the start
method to
resume animation, and the stop
method to suspend the
animation.
The implementation of this method provided by the
Applet
class does nothing.
paint(g)
. This method was overridden to
prevent an unnecessary call to clear the background.
The validate
method is used to cause a container
to lay out its subcomponents again. It should be invoked when
this container's subcomponents are modified (added to or
removed from the container, or layout-related information
changed) after the container has been displayed.
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.