Download AWT

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Support Readiness Document
Java™ 2 Standard Edition,
Version 1.4
Abstract Window Toolkit (AWT)
Sun Microsystems, Inc.
901 San Antonio Road
Palo Alto, CA 94303
U.S.A. 650-960-1300
March 2002
 2002 by Sun Microsystems, Inc.—Printed in USA.
901 San Antonio Road, Palo Alto, CA 94303-4900
All rights reserved. No part of this work covered by copyright may be duplicated by any means—graphic, electronic or mechanical,
including photocopying, or storage in an information retrieval system—without prior written permission of the copyright owner.
RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the government is subject to restrictions as set forth in
subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 252.227-7013 (October 1988) and FAR
52.227-19 (June 1987). The product described in this manual may be protected by one or more U.S. patents, foreign patents, and/or
pending applications.
TRADEMARKS: Java, Java 2 Platform, J2SE, Java 2 Enterprise Edition, J2EE, Java 2 SDK, JDK, Javadocs, Java 2D, Solaris, and Sun are
trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. UNIX is a registered
trademark in the United States and other countries, exclusively licensed through X/Open Company, Ltd. Netscape is a trademark or
registered trademark of Netscape Communications Corporation.
Sun Microsystems, Inc.
Table of Contents
1.
2.
Abstract Window Toolkit Overview 1
1.1
Overview
1
1.2
Scope
1.3
Introduction to AWT
1
2
Product Changes for Version 1.4 3
2.1
Changes and New Features in Version 1.4
2.1.1
New Focus Architecture
2.1.2
Full-Screen Mode
3
2.1.3
Headless Support
4
2.1.4
Native Frame Decorations
2.1.5
Mouse Wheel
2.1.6
64-bit Support
3
4
4
4
2.2
Bugs Fixed in Version 1.4
2.3
Product Additions for AWT, V. 1.4
2.3.1
3
4
5
New Classes and Interfaces
5
2.3.1.1
Display and Buffer
2.3.1.2
Focus
2.3.1.3
Mouse Wheel
2.3.1.4
Window Events
2.3.1.5
Keyboard
2.3.1.6
ScrollPane
5
5
6
7
7
7
Sun Microsystems, Inc.
Table of Contents
iii
2.3.1.7
2.3.2
Event
7
New Methods and Fields
7
2.3.2.1
java.awt.AWTEvent
2.3.2.2
java.awt.AWTEventMulticaster
2.3.2.3
java.awt.BorderLayout
2.3.2.4
java.awt.Button
8
2.3.2.5
java.awt.Canvas
9
2.3.2.6
java.awt.Checkbox
2.3.2.7
java.awt.CheckboxMenuItem
2.3.2.8
java.awt.Choice
2.3.2.9
java.awt.Component
9
2.3.2.10
java.awt.Container
13
2.3.2.11
java.awt.Dialog
2.3.2.12
java.awt.EventQueue
2.3.2.13
java.awt.Font
2.3.2.14
java.awt.Frame
2.3.2.15
java.awt.GraphicsConfiguration
2.3.2.16
java.awt.GraphicsDevice
2.3.2.17
java.awt.GraphicsEnvironment
2.3.2.18
java.awt.GridBagLayout 16
2.3.2.19
java.awt.Label 17
2.3.2.20
java.awt.List
2.3.2.21
java.awt.MenuItem 17
2.3.2.22
java.awt.Polygon 17
2.3.2.23
java.awt.Robot
2.3.2.24
java.awt.ScrollPane 18
2.3.2.25
java.awt.ScrollBar
2.3.2.26
java.awt.TextComponent 18
2.3.2.27
java.awt.TextField
2.3.2.28
java.awt.Toolkit 19
2.3.2.29
java.awt.Window
2.3.2.30
java.awt.event.ActionEvent
Sun Microsystems, Inc.
8
8
8
9
9
9
14
14
14
14
15
15
16
17
17
18
19
20
21
Table of Contents
iv
2.3.3
3.
4.
5.
2.3.2.31
java.awt.event.AdjustmentEvent
2.3.2.32
java.awt.event.FocusEvent
2.3.2.33
java.awt.event.InputMethodEvent
2.3.2.34
java.awt.event.InvocationEvent
2.3.2.35
java.awt.event.WindowAdapter
2.3.2.36
java.awt.WindowEvent
New Runtime Flags
22
22
22
22
22
23
23
2.3.3.1
java.awt.headless
23
2.3.3.2
sun.awt.noerasebackground
23
2.4
Backward and Forward Compatibility With Other Versions
2.5
Upgrading to Version 1.4 From a Previous Version
2.6
Porting Applications to Version 1.4
23
24
24
Using and Supporting AWT 25
3.1
User’s Guides and Tutorials
3.2
Additional Resources
25
25
Code Samples 27
4.1
Full Screen Mode and Buffering
4.2
Extended State
4.3
Focus Events
4.4
Mouse Wheel Behavior
4.5
Undecorated Frames
27
32
34
36
37
Troubleshooting 39
5.1
Troubleshooting Tips
5.2
Common Developer Problems
5.3
39
39
5.2.1
AWT Threading
39
5.2.2
Painting of Components
5.2.3
Focus Problems
5.2.4
Mixing Lightweight and Heavyweight Components
39
40
Known Bugs and Their Workarounds
Sun Microsystems, Inc.
40
40
Table of Contents
v
5.4
Error Message Guide
40
6.
Installing and Configuring AWT 41
7.
Reference Information 42
7.1
Product Information
42
7.2
Technical Documentation
7.3
Tutorials and Other References
42
42
Sun Microsystems, Inc.
Table of Contents
vi
Preface
This document provides support readiness information for the Abstract Window
Toolkit, which is part of the Java 2 Platform, Standard Edition (J2SE™), version
1.4.
This document is not designed to provide comprehensive product training.
Instead, it focuses on issues immediately relevant to support, such as changes in
this version of the product, using and troubleshooting the product, and
installing and configuring the product. For pointers to other documentation, see
Section 7 “Reference Information.”
Sun Microsystems, Inc.
Preface
vii
1
Abstract Window Toolkit Overview
The following SRD may contain actual software programs in source code form.
This source code is made available for developers to use as needed, pursuant to
the terms and conditions of this license located at:
http://access1.sun.com/SRDs/BSD.html
1.1
Overview
This document provides Support Readiness information for the AWT. The AWT
is part of the Java Foundation Classes (JFC) and enables graphical user interface
(GUI) programming and design. Currently, using Swing, the part of the JFC that
implements a new set of GUI components, is the preferred way of developing
GUIs in the Java programming language. However, the AWT is still heavily
used both by legacy code and new code. Swing itself is built on top of the AWT.
For these reasons, the AWT remains a crucial public application programming
interface (API) in the Java programming language.
This document covers the changes in the AWT for J2SE Software Development
Kit (J2SDK), version 1.4.
Note – This document focuses on the core Java 2 Platform AWT. The new
Java 2D and Drag and Drop APIs are discussed in separate Support Readiness
Documents (SRD).
1.2
Scope
This document only covers the AWT java.awt and java.awt.Event
packages in the J2SDK, v. 1.4
Sun Microsystems, Inc.
1 of 43
1.3
Introduction to AWT
An overview of AWT can be found at:
http://java.sun.com/j2se/1.4/docs
Sun Microsystems, Inc.
2 of 43
2
Product Changes for Version 1.4
2.1
Changes and New Features in Version 1.4
Changes to the AWT package center on improving the robustness, behavior, and
performance of programs that present a GUI.
The following paragraphs summarize the changes made in version 1.4.
The AWT release notes for J2SDK, v. 1.4, are available at:
http://java.sun.com/j2se/1.4/relnotes.html#awt
A description of the enhancements and changes made to AWT for J2SDK, v. 1.4,
can be found at:
http://java.sun.com/j2se/1.4/docs/guide/awt/
AWTChanges.html
2.1.1
New Focus Architecture
A new focus architecture replaces the previous implementation and addresses
many focus-related bugs caused by platform inconsistencies and
incompatibilities between AWT and Swing components.
2.1.2
Full-Screen Mode
The new full-screen exclusive mode API supports high performance graphics by
suspending the windowing system so that drawing can be done directly to the
screen, which is a benefit to applications, such as games or other renderingintensive applications.
Sun Microsystems, Inc.
3 of 43
2.1.3
Headless Support
Headless support is now enabled by new graphics environment methods that
indicate whether a display, a keyboard, and a mouse can be supported in a
graphics environment. Headless support is provided to make porting the Java
platform easier to devices that do not have traditional input/output devices
attached.
2.1.4
Native Frame Decorations
The ability to disable native frame decorations is now available for applications
which need to take full control of specifying how a frame will look. When
enabled, this feature prevents the rendering of a native titlebar, system menu,
border, or other native operating system dependent screen components.
2.1.5
Mouse Wheel
The oft-requested mouse wheel with a scroll wheel in place of the middle mouse
button is enabled with new built-in Java support for scrolling using the mouse
wheel. Also, a new mouse wheel listener class allows customization of mouse
wheel behavior.
2.1.6
64-bit Support
The AWT package has been modified to be fully 64-bit compliant and now runs
on Solaris machines with 64-bit and 32-bit addresses.
2.2
Bugs Fixed in Version 1.4
The focus subsystem has been completely redesigned, and many focus bugs
were resolved.
Sun Microsystems, Inc.
4 of 43
2.3
Product Additions for AWT, V. 1.4
2.3.1
New Classes and Interfaces
The following sections discuss the new classes and interfaces added to AWT for
J2SDK, v. 1.4. They are sorted by area.
2.3.1.1
Display and Buffer
■
java.awt.BufferCapabilities - This is the capabilities and properties of
buffers.
public class BufferCapabilities
■
java.awt.DisplayMode - The DisplayMode class encapsulates the bit
depth, height, width, and refresh rate of a GraphicsDevice.
public final class DisplayMode
■
java.awt.HeadlessException - This exception is hrown when code that
is dependent on a keyboard, display, or mouse is called in an environment
that does not support a keyboard, display, or mouse.
public class HeadlessException
extends UnsupportedOperationException
■
java.awt.ImageCapabilities - This is the capabilities and properties of
images.
public class ImageCapabilities
implements Cloneable
2.3.1.2
Focus
■
java.awt.ContainerOrderFocusTransversalPolicy FocusTraversalPolicy determines traversal order based on the order of
child Components in a Container.
public class ContainerOrderFocusTraversalPolicy
extends FocusTraversalPolicy
implements Serializable
■
java.awt.DefaultKeyboardFocusManager - This is the default
KeyboardFocusManager for AWT applications.
public class DefaultKeyboardFocusManager
extends KeyboardFocusManager
Sun Microsystems, Inc.
5 of 43
■
java.awt.FocusTransversalPolicy - FocusTraversalPolicy
determines the traversal order based on the order of child Components in a
Container.
public class DefaultFocusTraversalPolicy
extends ContainerOrderFocusTraversalPolicy
■
java.awt.FocusTraversalPolicy - A FocusTraversalPolicy defines
the order in which Components with a particular focus cycle root are
traversed.
public abstract class FocusTraversalPolicy
■
java.awt.KeyEventDispatcher - A KeyEventDispatcher cooperates
with the current KeyboardFocusManager in the targeting and dispatching
of all KeyEvents.
public interface KeyEventDispatcher
■
java.awt.KeyEventPostProcessor - A KeyEventPostProcessor
cooperates with the current KeyboardFocusManagerin the final resolution
of all unconsumed KeyEvents.
public interface KeyEventPostProcessor
■
java.awt.KeyboardFocusManager - The KeyboardFocusManager is
responsible for managing the active and focused Windows and the current
focus owner.
public abstract class KeyboardFocusManager
implements KeyEventDispatcher, KeyEventPostProcessor
2.3.1.3
Mouse Wheel
■
java.awt.event.MouseWheelEvent - This event indicates that the mouse
wheel was rotated in a component.
public class MouseWheelEvent
extends MouseEvent
■
java.awt.event.MouseWheelListener - This is the listener interface for
receiving mouse wheel events on a component.
public interface MouseWheelListener
extends EventListener
Sun Microsystems, Inc.
6 of 43
2.3.1.4
Window Events
■
java.awt.event.WindowFocusListener - This is the listener interface for
receiving WindowEvents, including WINDOW_GAINED_FOCUS and
WINDOW_LOST_FOCUS events.
public interface WindowFocusListener
extends EventListener
■
java.awt.event.WindowStateListener - This is the listener interface for
receiving window state events.
public interface WindowStateListener
extends EventListener
2.3.1.5
Keyboard
■
java.awt.AWTKeyStroke - An AWTKeyStroke represents a key action on
the keyboard or equivalent input device.
public class AWTKeyStroke
implements Serializable
2.3.1.6
ScrollPane
■
java.awt.ScrollPaneAdjustable - This class represents the state of a
horizontal or vertical scrollbar of a ScrollPane.
public class ScrollPaneAdjustable
implements Adjustable, Serializable
2.3.1.7
Event
■
java.awt.event.AWTEventListenerProxy - This class extends the
EventListenerProxy, specifically for adding an AWTEventListener for a
specific event mask.
public class AWTEventListenerProxy
extends java.util.EventListenerProxy
implements AWTEventListener
2.3.2
New Methods and Fields
The following sections discuss the new methods and fields added to AWT for
J2SDK, v. 1.4. They are sorted by class.
Sun Microsystems, Inc.
7 of 43
2.3.2.1
java.awt.AWTEvent
■
This is the event mask for selecting mouse wheel events.
public final static long MOUSE_WHEEL_EVENT_MASK
■
This is the event mask for selecting window state events.
public final static long WINDOW_STATE_EVENT_MASK
■
This is the event mask for selecting window focus events.
public final static long WINDOW_FOCUS_EVENT_MASK
2.3.2.2
java.awt.AWTEventMulticaster
■
This handles the mouseWheelMoved event by invoking the
mouseWheelMoved methods on listener-a and listener-b.
public void mouseWheelMoved(MouseWheelEvent e)
■
This adds mouse-wheel-listener-a with mouse-wheel-listener-b and returns
the resulting multicast listener.
public static MouseWheelListener add(
MouseWheelListener a, MouseWheelListener b)
2.3.2.3
java.awt.BorderLayout
■
The component comes before the first line of the layout’s content.
public static final String PAGE_START
■
The component comes after the last line of the layout’s content.
public static final String PAGE_END
■
The component goes at the beginning of the line direction for the layout.
public static final String LINE_START
■
The component goes at the end of the line direction for the layout.
public static final String LINE_END
2.3.2.4
java.awt.Button
■
This returns an array of all the action listeners registered on this button.
public ActionListener[] getActionListeners()
Sun Microsystems, Inc.
8 of 43
2.3.2.5
java.awt.Canvas
■
This creates a new strategy for multi-buffering on this component.
public void createBufferStrategy(int numBuffers)
■
This creates a new strategy for multi-buffering on this component with the
required buffer capabilities.
public void createBufferStrategy(
int numBuffers, BufferCapabilities caps)
■
This returns the buffer strategy used by this component.
public BufferStrategy getBufferStrategy()
2.3.2.6
java.awt.Checkbox
■
This returns an array of all the item listeners registered on this checkbox.
public ItemListener[] getItemListeners()
2.3.2.7
java.awt.CheckboxMenuItem
■
This returns an array of all the item listeners registered on this checkbox
menu item.
public ItemListener[] getItemListeners()
2.3.2.8
java.awt.Choice
■
This returns an array of all the item listeners registered on this choice.
public ItemListener[] getItemListeners()
2.3.2.9
java.awt.Component
■
This is areference to a BufferStrategy object used to manipulate the
buffers on this Component.
transient BufferStrategy bufferStrategy
■
This is true when the object should ignore all repaint events.
boolean ignoreRepaint
■
This indicates whether this Component can be focused.
private boolean focusable
■
This tracks whether this Component is relying on default focus traversability.
private int isFocusTraversableOverridden
Sun Microsystems, Inc.
9 of 43
■
This sets the focus traversal keys.
Set[] focusTraversalKeys
■
This indicates whether or not the focus traversal keys are enabled for this
Component.
private boolean focusTraversalKeysEnabled
■
This returns whether or not the foreground color has been explicitly set for
this Component.
public boolean isForegroundSet()
■
This returns whether or not the background color has been explicitly set for
this Component.
public boolean isBackgroundSet()
■
This returns whether or not the font has been explicitly set for this
Component.
public boolean isFontSet()
■
This returns whether or not the cursor has been explicitly set for this
Component.
public boolean isCursorSet()
■
This creates a volatile off-screen drawable image with the given capabilities.
public VolatileImage createVolatileImage(
int width, int height,ImageCapabilities caps)
throws AWTException
■
This creates a volatile off-screen drawable image to be used for double
buffering.
public VolatileImage createVolatileImage(
int width, int height)
■
This creates a new strategy for multi-buffering on this component.
void createBufferStrategy(int numBuffers)
■
This creates a new strategy for multi-buffering on this component with the
required buffer capabilities.
void createBufferStrategy(
int numBuffers,BufferCapabilities caps)
throws AWTException
■
This return the buffer strategy used by this component
BufferStrategy getBufferStrategy()
■
This is the inner class for flipping buffers on a component.
protected class FlipBufferStrategy
extends BufferStrategy
Sun Microsystems, Inc.
10 of 43
■
This is the inner class for blitting offscreen surfaces to a component.
protected class BltBufferStrategy extends BufferStrategy
■
This sets whether or not paint messages received from the operating system
should be ignored.
public void setIgnoreRepaint(boolean ignoreRepaint)
■
This returns whether or not paint messages received from the operating
system should be ignored.
public boolean getIgnoreRepaint()
■
This returns an array of all the component listeners registered on this
Component.
public ComponentListener[] getComponentListeners()
■
This returns an array of all the focus listeners
public FocusListener[] getFocusListeners()
■
This returns whether this Component can be focused.
public boolean isFocusable()
■
This sets the focusable state of this Component to the specified value.
public void setFocusable(boolean focusable)
■
This sets the focus traversal keys for a given traversal operation for this
Component.
public void setFocusTraversalKeys(int id, Set keystrokes)
■
This returns the Set of focus traversal keys for a given traversal operation for
this Component.
public Set getFocusTraversalKeys(int id)
■
This returns whether the Set of focus traversal keys for the given focus
traversal operation has been explicitly defined for this Component.
public boolean areFocusTraversalKeysSet(int id)
■
This sets whether focus traversal keys are enabled for this Component.
public void setFocusTraversalKeysEnabled(
boolean focusTraversalKeysEnabled)
■
This returns whether focus traversal keys are enabled for this Component.
public boolean getFocusTraversalKeysEnabled()
■
This requests that this Component get the input focus and that this
Component’s top-level ancestor become the focused Window.
protected boolean requestFocus(boolean temporary)
■
This requests that this Component get the input focus if this Component’s
top-level ancestor is already the focused Window.
public boolean requestFocusInWindow()
Sun Microsystems, Inc.
11 of 43
■
This returns an array of all the hierarchy listeners registered on this
Component.
public HierarchyListener[] getHierarchyListeners()
■
This returns an array of all the hierarchy bounds listeners registered on this
Component.
public HierarchyBoundsListener[] getHierarchyBoundsListeners()
■
This returns an array of all the key listeners registered on this component.
public KeyListener[] getKeyListeners()
■
This returns an array of all the mouse listeners registered on this component.
public MouseListener[] getMouseListeners()
■
This returns an array of all the mouse motion listeners registered on this
component.
public MouseMotionListener[] getMouseMotionListeners()
■
This adds the specified mouse wheel listener to receive mouse wheel events
public void addMouseWheelListener(MouseWheelListener l)
■
This removes the specified mouse wheel listener so that it no longer receives
mouse wheel events from this component.
public void removeMouseWheelListener(MouseWheelListener l)
■
This returns an array of all the mouse wheel listeners registered on this
component.
public MouseWheelListener[] getMouseWheelListeners()
■
This returns an array of all the input method listeners registered on this
component.
public InputMethodListener[] getInputMethodListeners()
■
This processes mouse wheel events occurring on this component by
dispatching them to any registered MouseWheelListener objects.
protected void processMouseWheelEvent(MouseWheelEvent e)
■
This transfers the focus to the previous component as though this
Component.
public void transferFocusBackward()
■
This transfers the focus up one focus traversal cycle.
public void transferFocusUpCycle()
■
This returns an array of all the property change listeners registered on this
component.
public PropertyChangeListener[] getPropertyChangeListeners()
Sun Microsystems, Inc.
12 of 43
2.3.2.10
java.awt.Container
■
This is the focus traversal policy that will manage keyboard traversal of this
Container’s children if this Container is a focus cycle root.
private transient FocusTraversalPolicy focusTraversalPolicy
■
This indicates whether this Component is the root of a focus traversal cycle.
private boolean focusCycleRoot
■
This returns an array of all the container listeners registered on this
Container.
public ContainerListener[] getContainerListeners()
■
This sets the focus traversal keys for a given traversal operation for this
Container.
public void setFocusTraversalKeys(int id,Set keystrokes)
■
This returns whether the Set of focus traversal keys for the given focus
traversal operation has been explicitly defined for this Container.
public boolean areFocusTraversalKeysSet(int id)
■
This returns whether the specified Container is the focus cycle root of this
Container’s focus traversal cycle.
public boolean isFocusCycleRoot(Container container)
■
This sets the focus traversal policy that will manage keyboard traversal of this
Container’s children if this Container is a focus cycle root.
public void setFocusTraversalPolicy(FocusTraversalPolicy policy)
■
This returns the focus traversal policy that will manage keyboard traversal of
this Container’s children.
public FocusTraversalPolicy getFocusTraversalPolicy()
■
This returns whether the focus traversal policy has been explicitly set for this
Container.
public boolean isFocusTraversalPolicySet()
■
This sets whether this Container is the root of a focus traversal cycle.
public void setFocusCycleRoot(boolean focusCycleRoot)
■
This returns whether this Container is the root of a focus traversal cycle.
public boolean isFocusCycleRoot()
■
This sets the ComponentOrientation property of this container and all
components contained within it.
public void applyComponentOrientation( ComponentOrientation o)
■
This transfers the focus down one focus traversal cycle.
public void transferFocusDownCycle()
Sun Microsystems, Inc.
13 of 43
2.3.2.11
java.awt.Dialog
■
This field indicates whether or not the dialog is undecorated.
boolean undecorated = false;
■
This constructs an initially invisible Dialog with the specified owner frame,
title, modality, and GraphicsConfiguration.
public Dialog(Frame owner, String title,
boolean modal,GraphicsConfiguration gc)
■
This constructs an initially invisible Dialog with the specified owner dialog,
title, modality, and GraphicsConfiguration.
public Dialog(Dialog owner, String title,
boolean modal, GraphicsConfiguration gc)
■
This disables or enables decorations for this dialog.
public void setUndecorated(boolean undecorated)
■
This indicates whether this dialog is undecorated.
public boolean isUndecorated()
2.3.2.12
java.awt.EventQueue
■
This returns the timestamp of the most recent event that had a timestamp and
that was dispatched from the EventQueue associated with the calling thread.
public static long getMostRecentEventTime()
■
This returns the the event currently being dispatched by the EventQueue
associated with the calling thread.
public static AWTEvent getCurrentEvent()
2.3.2.13
java.awt.Font
■
This indicates whether or not this Font object has a transform that affects its
size in addition to the Size attribute.
public boolean isTransformed()
2.3.2.14
java.awt.Frame
■
This state bit indicates that frame is maximized in the horizontal direction.
public static final int MAXIMIZED_HORIZ;
■
This state bit indicates that frame is maximized in the vertical direction.
public static final int MAXIMIZED_VERT;
Sun Microsystems, Inc.
14 of 43
■
This state bit mask indicates that frame is fully maximized both horizontally
and vertically.
public static final int MAXIMIZED_BOTH
■
This represents the maximized bounds for this frame.
Rectangle maximizedBounds;
■
This field indicates whether or not the frame is undecorated.
boolean undecorated;
■
This gets the state of this frame.
public int getExtendedState()
■
This sets maximized bounds for this frame.
public void setMaximizedBounds(Rectangle bounds)
■
This gets maximized bounds for this frame.
public Rectangle getMaximizedBounds()
■
This disables or enables decorations for this frame.
public void setUndecorated(boolean undecorated)
■
This indicates whether or not this frame is undecorated.
public boolean isUndecorated()
2.3.2.15
java.awt.GraphicsConfiguration
■
This returns a VolatileImage with a data layout and color model
compatible with this GraphicsConfiguration, using the specified image
capabilities.
public VolatileImage createCompatibleVolatileImage(
int width, int height,ImageCapabilities caps)
■
This returns the buffering capabilities of this GraphicsConfiguration.
public BufferCapabilities getBufferCapabilities()
■
This returns the image capabilities of this GraphicsConfiguration.
public ImageCapabilities getImageCapabilities()
2.3.2.16
java.awt.GraphicsDevice
■
This determines if FullScreen is supported on a specific platform.
public boolean isFullScreenSupported()
■
This enters full-screen mode or returns to windowed mode.
public void setFullScreenWindow(Window w)
Sun Microsystems, Inc.
15 of 43
■
This returns the Window object representing the full-screen window.
public Window getFullScreenWindow()
■
This returns true if this GraphicsDevice is supported.
public boolean isDisplayChangeSupported()
■
This sets the display mode of this graphics device.
public void setDisplayMode(DisplayMode dm)
■
This returns the current display mode of this GraphicsDevice.
public DisplayMode getDisplayMode()
■
This returns all display modes available for this GraphicsDevice.
public DisplayMode[] getDisplayModes()
2.3.2.17
java.awt.GraphicsEnvironment
■
This tests whether or not a display, keyboard, and mouse can be supported in
this environment.
public static boolean isHeadless()
■
This returns the value of the property java.awt.headless.
private static boolean getHeadlessProperty()
■
This checks for the headless state and throw HeadlessException if
headless.
static void checkHeadless() throws HeadlessException
■
This returns whether or not a display, keyboard, and mouse can be supported
in this graphics environment.
public boolean isHeadlessInstance()
■
This returns the Point where Windows should be centered.
public Point getCenterPoint()
■
This returns the maximum bounds for centered Windows.
public Rectangle getMaximumWindowBounds()
2.3.2.18
java.awt.GridBagLayout
■
This fills in an instance of the above structure for the current set of managed
children.
protected GridBagLayoutInfo getLayoutInfo(
Container parent,int sizeflag)
■
This adjusts the x, y, width, and height fields to the correct values, depending
on the constraint geometry and pads.
Sun Microsystems, Inc.
16 of 43
protected void adjustForGravity(
GridBagConstraints constraints,Rectangle r)
■
This figures out the minimum size of the master based on the information
from getLayoutInfo().
protected Dimension getMinSize(
Container parent, GridBagLayoutInfo info)
■
This lays out the grid.
protected void arrangeGrid(Container parent)
2.3.2.19
java.awt.Label
■
This reads a label from an object input stream.
private void readObject(ObjectInputStream s)
2.3.2.20
java.awt.List
■
This returns an array of all the item listeners registered on this list.
public ItemListener[] getItemListeners()
■
This returns an array of all the action listeners registered on this list.
public ActionListener[] getActionListeners()
2.3.2.21
java.awt.MenuItem
■
This returns an array of all the action listeners
public ActionListener[] getActionListeners()
2.3.2.22
java.awt.Polygon
■
This resets this Polygon object to an empty polygon.
public void reset()
■
This invalidates or flushes any internally-cached data that depends on the
vertex coordinates of this Polygon.
public void invalidate()
2.3.2.23
java.awt.Robot
■
This rotates the scroll wheel on wheel-equipped mice.
public void mouseWheel(int wheelAmt)
Sun Microsystems, Inc.
17 of 43
2.3.2.24
java.awt.ScrollPane
■
This indicates whether or not scrolling should take place.
private boolean wheelScrollingEnabled
■
This processes mouse wheel events that are delivered to this ScrollPane by
scrolling an appropriate amount.
protected void processMouseWheelEvent(MouseWheelEvent e)
■
If wheel scrolling is enabled, this returns true for MouseWheelEvents.
protected boolean eventTypeEnabled(int type)
■
This enables or disables scrolling in response to movement of the mouse
wheel.
public void setWheelScrollingEnabled(boolean handleWheel)
■
This indicates whether or not scrolling will take place in response to the
mouse wheel. Wheel scrolling is enabled by default.
public boolean isWheelScrollingEnabled()
2.3.2.25
java.awt.ScrollBar
■
This is the adjusting status of the Scrollbar.
transient boolean isAdjusting;
■
This returns true if the value is in the process of changing as a result of
actions being taken by the user.
public boolean getValueIsAdjusting()
■
This sets the valueIsAdjusting property. Parameter b is the new
adjustment-in-progress status.
public void setValueIsAdjusting(boolean b)
■
This returns an array of all the adjustment listeners registered on this
scrollbar.
public AdjustmentListener[] getAdjustmentListeners()
2.3.2.26
java.awt.TextComponent
■
This returns an array of all the text listeners registered on this text
component.
public TextListener[] getTextListeners()
Sun Microsystems, Inc.
18 of 43
2.3.2.27
java.awt.TextField
■
This returns an array of all the action listeners registered on this textfield.
public ActionListener[] getActionListeners()
2.3.2.28
java.awt.Toolkit
■
This gets the singleton instance of the system selection as a Clipboard
object.
public Clipboard getSystemSelection()
■
This returns an array of all the property change listeners registered on this
toolkit.
public PropertyChangeListener[] getPropertyChangeListeners()
■
This returns an array of all the PropertyChangeListeners associated with
the named property.
public PropertyChangeListener[] getPropertyChangeListeners(
String propertyName)
■
This returns an array of all the AWTEventListeners registered on this
toolkit.
public AWTEventListener[] getAWTEventListeners()
■
This returns an array of all the AWTEventListeners.
public AWTEventListener[] getAWTEventListeners(long eventMask)
■
This gets the insets of the screen.
public Insets getScreenInsets(GraphicsConfiguration gc)
■
This controls whether the layout of Containers is validated dynamically
during resizing, or statically, after resizing is complete.
public void setDynamicLayout(boolean dynamic)
■
This returns whether the layout of Containers is validated dynamically
during resizing or statically after resizing is complete.
protected boolean isDynamicLayoutSet()
■
This returns whether dynamic layout of Containers on resize is currently
active (both set programmatically and supported by the underlying operating
system or window manager).
public boolean isDynamicLayoutActive()
■
This returns whether Toolkit supports this state for Frames.
public boolean isFrameStateSupported(int state)
Sun Microsystems, Inc.
19 of 43
2.3.2.29
java.awt.Window
■
This indicates whether this Window can become the focused Window.
private boolean focusableWindowState
■
This adds the specified window state listener to receive window events from
this window.
public void addWindowStateListener(WindowStateListener l)
■
This removes the specified window state listener so that it no longer receives
window events from this window.
public void removeWindowStateListener( WindowStateListener l)
■
This returns an array of all the window listeners registered on this window.
public WindowListener[] getWindowListeners()
■
This returns an array of all the window focus listeners registered on this
window.
public WindowFocusListener[] getWindowFocusListeners()
■
This returns an array of all the window state listeners registered on this
window.
public WindowStateListener[] getWindowStateListeners()
■
This processes window state events occuring on this window by dispatching
them to any registered WindowStateListener objects.
protected void processWindowStateEvent(WindowEvent e)
■
This returns the child Component of this Window that will receive the focus
when this Window is focused.
public Component getMostRecentFocusOwner()
■
This returns whetheror not this Window is active.
public boolean isActive()
■
This returns whether or not this Window is focused.
public boolean isFocused()
■
This gets a focus traversal key for this Window.
public Set getFocusTraversalKeys(int id)
■
This does nothing because Windows must always be roots of a focus traversal
cycle.
public final void setFocusCycleRoot(boolean focusCycleRoot)
■
This always returns true because all Windows must be roots of a focus
traversal cycle.
public final boolean isFocusCycleRoot()
Sun Microsystems, Inc.
20 of 43
■
This always returns null because Windows have no ancestors. They represent
the top of the Component hierarchy.
public final Container getFocusCycleRootAncestor()
■
This returns whether or not this Window can become the focused Window,
that is, whether or not this Window or any of its subcomponents can become
the focus owner.
public final boolean isFocusableWindow()
■
This returns whether this Window can become the focused Window, that is,
whether this Window or any of its subcomponents can become the focus
owner.
public final boolean isFocusableWindow()
■
This returns whether or not this Window can become the focused Window if it
meets the other requirements outlined in isFocusableWindow.
public boolean getFocusableWindowState()
■
This sets whether this Window can become the focused Window if it meets the
other requirements outlined in isFocusableWindow.
public void setFocusableWindowState(boolean focusableWindowState)
■
This sets the location of the window relative to the specified component.
public void setLocationRelativeTo(Component c)
■
This creates a new strategy for multi-buffering on this component.
public void createBufferStrategy(int numBuffers)
■
This creates a new strategy for multi-buffering on this component with the
required buffer capabilities.
public void createBufferStrategy(
int numBuffers,BufferCapabilities caps)
■
This returns the buffer strategy used by this component
public BufferStrategy getBufferStrategy()
2.3.2.30
java.awt.event.ActionEvent
■
This constructs an ActionEvent object with the specified modifier keys and
timestamp.
public ActionEvent(Object source, int id, String command,
long when, int modifiers)
■
This returns the timestamp of when this event occurred.
public long getWhen()
Sun Microsystems, Inc.
21 of 43
2.3.2.31
java.awt.event.AdjustmentEvent
■
The isAdjusting is true if the event is one of the series of multiple
adjustment events.
boolean isAdjusting;
2.3.2.32
java.awt.event.FocusEvent
■
This the other Component involved in this focus change.
Component opposite;
■
This returns the other Component involved in this focus change.
public Component getOppositeComponent()
2.3.2.33
java.awt.event.InputMethodEvent
■
This is the time stamp that indicates when the event was created.
long when;
■
This constructs an InputMethodEvent with the specified source component,
type, time, text, caret, and visiblePosition.
public InputMethodEvent(Component source, int id, long when,
AttributedCharacterIterator text,
int committedCharacterCount,TextHitInfo caret,
TextHitInfo visiblePosition)
■
This returns the time stamp when this event occurred.
public long getWhen()
2.3.2.34
java.awt.event.InvocationEvent
■
This returns the time stamp when this event occurred.
public long getWhen()
2.3.2.35
java.awt.event.WindowAdapter
■
This is invoked when the window state has changed
public void windowStateChanged(WindowEvent e)
■
This is invoked when the Window is set to be the focused Window.
public void windowGainedFocus(WindowEvent e)
■
This is invoked when the Window is no longer the focused Window.
public void windowLostFocus(WindowEvent e)
Sun Microsystems, Inc.
22 of 43
2.3.2.36
java.awt.WindowEvent
■
This is the window-state-changed event type.
public static final int WINDOW_STATE_CHANGED
■
This constructs a WindowEvent object.
public WindowEvent(Window source, int id,
Window opposite, int oldState, int newState)
■
This constructs a WindowEvent object with the specified:
public WindowEvent(Window source, int id, int oldState, int newState)
■
This returns the other Window involved in this focus or activation change.
public Window getOppositeWindow()
■
For WINDOW_STATE_CHANGED events, this returns the previous state of the
window.
public int getOldState()
■
For WINDOW_STATE_CHANGED events, this returns the new state of the
window.
public int getNewState()
2.3.3
New Runtime Flags
2.3.3.1
java.awt.headless
When java.awt.headless is true, a java.awt.HeadlessException will be
thrown when any instance of a class creates a screen, mouse, or keyboard
resource.
2.3.3.2
sun.awt.noerasebackground
When sun.awt.noerasebackground is true, the background of any heavy
weight component will not be erased on the Microsoft Windows platform. This
means the application programmer is responsible for painting the background.
2.4
Backward and Forward Compatibility With
Other Versions
AWT, v. 1.4, is backwardly compatible with version 1.2, which includes both
versions 1.2 and 1.3.
Sun Microsystems, Inc.
23 of 43
2.5
Upgrading to Version 1.4 From a Previous
Version
Upgrading AWT is included with the installation of J2SDK, v. 1.4.
2.6
Porting Applications to Version 1.4
Applications that work with versions 1.2 and 1.3 of AWT should require no
changes to continue working with AWT, v. 1.4.
Sun Microsystems, Inc.
24 of 43
3
Using and Supporting AWT
3.1
User’s Guides and Tutorials
The primary technical documentation for the AWT is the Javadoc comments in
the source code, which comprise the Java 2 Platform API Specification. To view
this documentation online, see:
http://www.java.sun.com/products/jdk/1.4/docs/api/
index.html
Online tutorials and articles can be found at:
http://java.sun.com/docs/books/tutorial/
3.2
Additional Resources
The Java Developer Connection contains additional technical information, news,
user forums, and support information.
Note – Free registration required.
For more information, see:
http://developer.java.sun.com/developer/
The Focus specificiation can be found at:
http://java.sun.com/j2se/1.4/docs/api/java/awt/doc-files/
FocusSpec.html
Sun Microsystems, Inc.
25 of 43
The Java Series books, in particular those focusing on the Java Class Libraries,
provide additional AWT references. These books are listed on the Sun Java
Software Web page. For more information, see:
http://java.sun.com/
Sun Microsystems, Inc.
26 of 43
4
Code Samples
This section illustrates some of the new features in AWT for J2SE v. 1.4. The
following section may contain actual software programs in source code form.
This source code is made available for developers to use as needed, pursuant to
the terms and conditions of this license located at:
http://access1.sun.com/SRDs/BSD.html
4.1
Full Screen Mode and Buffering
The program MultiBufferDuke.java demonstrates the full screen mode and
how to use buffering to obtain high speed animation. This program uses a small
image file called duke.gif. To run this program, substitute any small .gif file
for duke.gif and modify the method initOffscreen() to use this .gif file.
import
import
import
import
import
import
import
import
import
import
java.awt.*;
java.awt.event.*;
java.awt.geom.Ellipse2D;
java.awt.geom.Arc2D;
java.awt.geom.AffineTransform;
java.awt.image.BufferedImage;
java.awt.image.BufferStrategy;
java.awt.image.VolatileImage;
java.net.URL;
javax.swing.*;
public class MultiBufferDuke extends JFrame
implements Runnable, ActionListener {
private static final int MAX_BUFFERS = 7;
private
private
private
private
static
static
static
static
int spriteW, spriteH;
int labelHeight = 15;
Image dukeImage;
VolatileImage sprite;
private GraphicsDevice device;
private int numBuffers;
Sun Microsystems, Inc.
27 of 43
private DisplayMode displayMode;
private JButton canvas = new JButton();
private Object exitLock = new Object();
private boolean quit = false;
private int xLoc = 0, yLoc = 0;
private int xStep = 7, yStep = 3;
private boolean isFullScreen;
private JButton quitButton = new JButton("Quit") {
public boolean hasFocus() {
return true;
}
};
private JPanel panel = new JPanel();
private BufferStrategy strat;
public MultiBufferDuke(GraphicsDevice device, int numBuffers,
DisplayMode displayMode) {
super("Java AWT(TM) Demo - MultiBufferDuke");
this.device = device;
this.numBuffers = numBuffers;
this.displayMode = displayMode;
this.isFullScreen = device.isFullScreenSupported();
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent ev) {
System.exit(0);
}
});
setBackground(Color.blue);
setForeground(Color.red);
setUndecorated(isFullScreen);
setResizable(!isFullScreen);
setIgnoreRepaint(true);
getContentPane().setLayout(new BorderLayout());
canvas.setPreferredSize(
new Dimension(displayMode.getWidth(),
displayMode.getHeight() * 3 / 4 +
displayMode.getHeight() * 3 % 4));
getContentPane().add(canvas, BorderLayout.CENTER);
panel.setLayout(new FlowLayout(FlowLayout.RIGHT));
panel.setPreferredSize(new Dimension(1,1
//displayMode.getWidth(),
//displayMode.getHeight() / 4
));
getContentPane().add(panel, BorderLayout.NORTH);
panel.add(quitButton);
quitButton.addActionListener(this);
Sun Microsystems, Inc.
28 of 43
canvas.addActionListener(this);
}
public void paint(Graphics g) {
}
public void start() {
if (isFullScreen) {
// Full-screen mode
try {
device.setFullScreenWindow(this);
if (displayMode != null) {
device.setDisplayMode(displayMode);
}
createBufferStrategy(numBuffers);
strat = getBufferStrategy();
Thread t = new Thread(this);
t.start();
synchronized(exitLock) {
try { exitLock.wait(); } catch (
InterruptedException e) {}
}
//run();
} finally {
device.setFullScreenWindow(null);
}
} else {
// Windowed mode
pack();
setVisible(true);
createBufferStrategy(numBuffers);
strat = getBufferStrategy();
run();
}
}
/**
* Prepare the sprite location variables for the next frame
*/
public void step() {
xLoc += xStep;
yLoc += yStep;
if ((xLoc < 0) ||
(xLoc + spriteW) > canvas.getWidth()) {
xLoc -= 2 * xStep;
xStep = -xStep;
}
if ((yLoc < panel.getHeight()) || // if ((yLoc < 0) ||
(yLoc + spriteH) > canvas.getHeight()) {
yLoc -= 2 * yStep;
yStep = -yStep;
Sun Microsystems, Inc.
29 of 43
}
}
/**
* For any of our images that are volatile, if the contents of
* the image have been lost since the last reset, reset the image
* and restore the contents. Note that these operations may not
* succeed (if the surfaces are not yet restoreable), but we will
* stay in our rendering loop and keep calling this method until
* we succeed.
*/
public void resetRestoreVolatileImages() {
if (sprite.contentsLost()) {
sprite.validate(getGraphicsConfiguration());
restoreSpriteContent();
}
}
public void run() {
int counter = 0;
int panelHeight = panel.getHeight();
Insets insets;
if (isFullScreen) {
insets = new Insets(0,0,0,0);
} else {
insets = getInsets();
}
yLoc = panelHeight + insets.top;
while (!quit) {
step();
// First, set up default content for onscreen window.
// We should never see this content (except perhaps in
// transition as the window is updating). Instead, it
// should be covered over by the content from the
// offscreen surface. If we see the yellow text on blue
// background, then something is wrong.
initOffscreen();
//repaint();
// Render the back buffer and copy it to the screen. Loop
// until the buffer contents are correct (this will only
// loop when/if surface are lost, causing content loss on
// volatile images).
try {
//long startTime = System.currentTimeMillis();
do {
resetRestoreVolatileImages();
Graphics g = strat.getDrawGraphics();
g.setColor(Color.green);
g.fillRect(
1 + insets.left,
Sun Microsystems, Inc.
30 of 43
1 + panelHeight + insets.top,
canvas.getWidth() -1,
canvas.getHeight()-1);
g.setColor(Color.black);
g.drawRect(
insets.left, panelHeight + insets.top,
canvas.getWidth()-1,
canvas.getHeight()-1);
g.drawImage((Image)sprite, xLoc, yLoc, this);
g.setColor(Color.red);
g.drawString("Click Center And Wait to Exit",
5 + insets.left,
panel.getHeight() + 10 + insets.top);
panel.paint(g);
g.dispose();
} while (sprite.contentsLost());
strat.show();
//long stopTime = System.currentTimeMillis();
//System.out.println("Time " + (
// stopTime - startTime));
} catch (Exception e) {
System.out.println(
"Exception during paint: " + e);
e.printStackTrace();
System.exit(0);
}
}
exit();
}
public void actionPerformed(ActionEvent ev) {
quit = true;
}
/**
* Load the duke.gif image, create the sprite and back buffer
* images, and render the content into the sprite.
*/
public void initOffscreen() {
if (dukeImage == null) {
dukeImage = new ImageIcon("duke.gif").getImage();
spriteW = dukeImage.getWidth(null);
spriteH = dukeImage.getHeight(null) + labelHeight;
sprite = createVolatileImage(spriteW, spriteH);
restoreSpriteContent();
}
}
/**
* Renders the sprite that we will use. We fill the sprite
* with a background color, copy in the image that we loaded,
Sun Microsystems, Inc.
31 of 43
* and label the sprite according to its volatility setting.
*/
public void restoreSpriteContent() {
Graphics2D g2 = (Graphics2D)((Image)sprite).getGraphics();
g2.setColor(Color.green);
g2.fillRect(0, 0, spriteW, spriteH);
g2.drawImage(dukeImage, null, null);
g2.dispose();
}
public void exit() {
synchronized(exitLock) {
exitLock.notifyAll();
}
}
public static void main(String args[]) {
int numBuffers = 2;
GraphicsDevice device = GraphicsEnvironment.
getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode dm = new DisplayMode(640, 480, 32, 0);
MultiBufferDuke test = new MultiBufferDuke(
device, numBuffers, dm);
test.start();
System.exit(0);
}
}
4.2
Extended State
The program extendedState.java demonstrates the getExtendedState
and setExtendedState API.
import java.awt.*;
import java.awt.event.*;
public class extendedState extends Frame implements
WindowStateListener
{
extendedState()
{
super("extendedState");
setResizable(false);
setLayout(new GridLayout(1,3));
Button maximizeButton = new Button("Maximize");
if (Toolkit.getDefaultToolkit().isFrameStateSupported(
Frame.MAXIMIZED_BOTH))
{
add(maximizeButton);
32 of 43 - SRD for AWT, V. 1.4 - February 2002
SUN CONFIDENTIAL
}
maximizeButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
onMaximize();
}
}
);
Button iconifyButton = new Button("Iconify");
if (Toolkit.getDefaultToolkit().isFrameStateSupported(
Frame.ICONIFIED))
{
add(iconifyButton);
}
iconifyButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
onIconify();
}
}
);
addWindowStateListener(this);
addExitHandler();
pack();
show();
}
void onMaximize()
{
setExtendedState(Frame.MAXIMIZED_BOTH);
}
void onIconify()
{
setExtendedState(Frame.ICONIFIED);
}
public void windowStateChanged(WindowEvent e)
{
System.out.println("windowStateChanged " + e.toString());
}
void addExitHandler()
{
Button exitButton = new Button("Exit");
add(exitButton);
Sun Microsystems, Inc.
33 of 43
exitButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
);
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
public static void main(String[] args)
{
extendedState frame = new extendedState();
}
}
4.3
Focus Events
The program focus.java demonstrates the focus gained and lost events.
import java.awt.*;
import java.awt.event.*;
public class focus extends Frame
{
focus()
{
super("focus");
setLayout(new GridLayout(1,4));
setResizable(false);
addExitHandlers();
add(new Button("Button"));
add(new Checkbox("CheckBox"));
java.awt.List list = new java.awt.List();
list.add(new String("item 1"));
list.add(new String("item 2"));
list.addFocusListener(
new FocusAdapter()
34 of 43 - SRD for AWT, V. 1.4 - February 2002
SUN CONFIDENTIAL
{
public void focusGained(FocusEvent e)
{
System.out.println("focusGained");
}
public void focusLost(FocusEvent e)
{
System.out.println("focusLost");
}
}
);
add(list);
Window window = new Window(this);
window.setLayout(new FlowLayout());
window.add(new Button("Button"));
window.add(new TextField(20));
window.setLocation(100,100);
window.pack();
window.show();
pack();
show();
}
void addExitHandlers()
{
Button button = new Button("Exit");
add(button);
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
);
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
public static void main(String[] args)
{
Sun Microsystems, Inc.
35 of 43
focus frame = new focus();
}
}
4.4
Mouse Wheel Behavior
The program mouseWheel.java demonstrates mouse wheel default and
programmed behavior.
import java.awt.*;
import java.awt.event.*;
public class mouseWheel extends Frame implements MouseWheelListener
{
Label label;
mouseWheel()
{
super("mouseWheel");
setResizable(false);
setLayout(new GridLayout(3,1));
addExitHandlers();
java.awt.List list = new java.awt.List();
list.add(new String("MouseWheel Here"));
for (int i = 2; i < 25; i++)
list.add(new String("Item: " + i));
add(list);
label = new Label(new String("MouseWheel Here"));
add(label);
label.addMouseWheelListener(this);
pack();
show();
}
public void mouseWheelMoved(MouseWheelEvent e)
{
label.setText(new String(
"Mouse Wheel Here " + e.getWheelRotation()));
}
private void addExitHandlers()
{
Button button = new Button("Exit");
add(button);
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
36 of 43 - SRD for AWT, V. 1.4 - February 2002
SUN CONFIDENTIAL
System.exit(0);
}
}
);
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
public static void main(String[] args)
{
mouseWheel frame = new mouseWheel();
}
}
4.5
Undecorated Frames
The program undecorated.java demonstrates frames and dialogs without
decorations.
import java.awt.*;
import java.awt.event.*;
public class undecorated extends Frame
{
undecorated()
{
super("undecorated");
setUndecorated(true);
setResizable(false);
setLocation(100,100);
setLayout(new GridLayout(2,1));
Button dialogButton = new Button("Dialog");
add(dialogButton);
dialogButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
onDialog();
}
}
);
Sun Microsystems, Inc.
37 of 43
Button exitButton = new Button("Exit");
add(exitButton);
exitButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
);
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
pack();
show();
}
void onDialog()
{
final Dialog dialog = new Dialog(this,"dialog",true);
dialog.setUndecorated(true);
dialog.setLocation(150,150);
Button button = new Button("close");
dialog.add(button);
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
dialog.dispose();
}
}
);
dialog.pack();
dialog.show();
}
public static void main(String[] args)
{
undecorated frame = new undecorated();
}
}
38 of 43 - SRD for AWT, V. 1.4 - February 2002
SUN CONFIDENTIAL
5
Troubleshooting
5.1
Troubleshooting Tips
The quickest way to find out what is happening in a Java program is to add
System.out.println(..) statements. The next thing to do to determine
program flow is to use the java.lang.Throwable.printStackTrace()
method.
5.2
Common Developer Problems
5.2.1
AWT Threading
AWT events must be handled in the AWTEventQueue thread. This occurs
automatically for single-threaded programs, but with multithreaded programs
care must be taken to handle all AWTEvents in the AWTEventQueue. To do this,
use the java.awt.EventQueue.invokeLater(..) method.
5.2.2
Painting of Components
Make sure all painting is done in the java.awt.Component paint(..)
method. Attempting to paint elsewhere will not work correctly.
Sun Microsystems, Inc.
39 of 43
5.2.3
Focus Problems
In version 1.4 the focus subsystem was completely redesigned but remains
API-level backwardly compatible. Some programs may not work exactly the
same way if they have workarounds for old focus bugs. Refer to the focus
specification referenced above.
5.2.4
Mixing Lightweight and Heavyweight
Components
In general, lightweight and heavyweight components should not be mixed. An
application should either be coded for AWT or Swing but not a combination of
the two. For example, do not add a java.awt.Button to a
javax.swing.JPanel.
5.3
Known Bugs and Their Workarounds
Refer to the Bug Parade:
http://developer.java.sun.com/developer/bugParade/
index.jshtml
5.4
Error Message Guide
Errors are handled through Java exceptions. Refer to the Javadoc for
java.awt.AWTException.
40 of 43 - SRD for AWT, V. 1.4 - February 2002
SUN CONFIDENTIAL
6
Installing and Configuring AWT
AWT is a component of the J2SDK. It is installed as part of the J2SDK, which can
be downloaded from:
http://java.sun.com/products/
For information on:
■
■
■
Downloading, installing, and uninstalling the J2SDK
Requirements and dependencies of the J2SDK
Product distribution and licensing of the J2SDK
Please see the J2SE Overview SRD available at:
http://access1.sun.com/SRDs/access1_srds.html
Sun Microsystems, Inc.
41 of 43
7
Reference Information
7.1
Product Information
■
The AWT release notes for J2SDK, v. 1.4, are available at:
http://java.sun.com/j2se/1.4/relnotes.html#awt
■
A description of the enhancements and changes made to AWT for J2SDK,
v. 1.4, can be found at:
http://java.sun.com/j2se/1.4/docs/guide/awt/
AWTChanges.html
7.2
Technical Documentation
■
J2SDK, Standard Edition, version 1.4, documentation is available at:
http://java.sun.com/j2se/1.4/docs
■
The Focus specificiation can be found at:
http://java.sun.com/j2se/1.4/docs/api/java/awt/doc-files/
FocusSpec.html
■
The API Guide for all of J2SDK is available at:
http://www.java.sun.com/products/jdk/1.4/docs/api/
index.html
7.3
Tutorials and Other References
■
Online tutorials and articles can be found at:
http://java.sun.com/docs/books/tutorial/
42 of 43 - SRD for AWT, V. 1.4 - February 2002
SUN CONFIDENTIAL
■
The Java Developer Connection contains additional technical information,
news, user forums, and support information.
http://developer.java.sun.com/developer/
Sun Microsystems, Inc.
43 of 43