The java.awt package contains what is known as the Java Abstract Windowing Toolkit. The classes within this package make up the pre-built graphical user interface components that are available to Java developers through the Java Developer's Kit. Classes defined within this package include such useful components as colors, fonts, and widgets, such as buttons and scrollbars. This package also defines two interfaces, LayoutManager and MenuContainer, as well as the exception AWTException and the error AWTError. The java.awt package also contains two subpackages: java.awt.image and java.awt.peer. This chapter documents all public instance variables and methods of each subpackage, class, interface, exception, and error in the java.awt package. Because the java.awt package is so large, Table 28.1 shows a complete list of its contents, and Figure 28.1 shows the hierarchy of the contents of that package.
Figure 28.1: Contents of package java.awt.
Class Index | Interface Index | |
BorderLayout | GridBagLayout | LayoutManager |
Button | GridLayout | MenuContainer |
Canvas | Image | |
CardLayout | Insets | |
Checkbox | Label | |
CheckboxGroup | List | |
CheckboxMenuItem | MediaTracker | |
Choice | Menu | |
Color | MenuBar | |
Component | MenuComponent | |
Container | MenuItem | |
Dialog | Panel | |
Dimension | Point | |
Event | Polygon | |
FileDialog | Rectangle | |
FlowLayout | Scrollbar | |
Font | TextArea | |
FontMetrics | TextComponent | |
Frame | TextField | |
Graphics | Toolkit | |
GridBagConstraints | Window |
Exception Index | Error Index |
AWTException | AWTError |
BorderLayout |
Object |
| LayoutManager |
The class hierarchy for the BorderLayout class derives from the class java.lang.Object. (See Listing 28.1.) A BorderLayout lays out components on a panel by implementing the LayoutManager interface. Components are laid out using members named North, South, East, West, and Center. BorderLayout's overall derivation is shown in Figure 28.1.
Listing 28.1. Public members of java.awt.BorderLayout.
public class BorderLayout implements LayoutManager {
public BorderLayout()
public BorderLayout(int hgap, int vgap)
public void addLayoutComponent(String name, Component comp)
public void removeLayoutComponent(Component comp)
public Dimension minimumLayoutSize(Container target)
public Dimension preferredLayoutSize(Container target)
public void layoutContainer(Container target)
public String toString()
}
BorderLayout | BorderLayout |
public BorderLayout()
This BorderLayout constructor constructs a BorderLayout layout manager.
| BorderLayout | BorderLayout |
public BorderLayout(int hgap, int vgap)
This BorderLayout constructor constructs a BorderLayout layout manager using the hgap and vgap values to set the horizontal and vertical gap sizes.
hgap is an integer value used to set the horizontal gap size. |
| vgap is an integer value used to set the vertical gap size. |
addLayoutComponent | BorderLayout |
public void addLayoutComponent(String name, Component comp)
addLayoutComponent adds a component to the BorderLayout according to that component's name (North, South, East, West, or Center). The component's preferred size is used for all layout types except Center.
name is a string value that must correspond to one of the following names: North, South, East, West, or Center. |
| comp is a component object to be added to this layout manager. |
removeLayoutComponent | BorderLayout |
public void removeLayoutComponent(Component comp)
removeLayoutComponent removes the specified component from the layout manager.
comp is the component object to be removed. |
minimumLayoutSize | BorderLayout |
public Dimension minimumLayoutSize(Container target)
minimumLayoutSize returns the minimum Dimension needed to lay out the components contained in the target parameter. Note that this function only determines the required size based on visible components.
target is a Container class containing components to be laid out. This class could be a Frame, Window, or any other class derived from the Container class. |
preferredLayoutSize | BorderLayout |
public Dimension preferredLayoutSize(Container target)
preferredLayoutSize returns the preferred Dimension needed to lay out the components contained in the target parameter. This Dimension is based on the individual component's preferred sizes. Note that this function only determines the required size based on visible components.
target is a Container class containing components to be laid out. This class could be a Frame, Window, or any other class derived from the Container class. |
layoutContainer | BorderLayout |
public void layoutContainer(Container target)
layoutContainer lays out the components contained in the target Container parameter. This method reshapes the components in the Container based on the requirements of the BorderLayout itself.
target is a Container class containing components to be laid out. This class could be a Frame, Window, or any other class derived from the Container class. |
toString | BorderLayout |
public String toString()
toString returns a string representation of the BorderLayout class.
A String value containing the BorderLayout class's name plus its hgap and vgap values (see the BorderLayout() constructor). |
| toString() in class Object. |
Button |
Component |
The class hierarchy for the Button class derives from the class java.awt.Component. (See Listing 28.2.) A Button can be placed on any type of layout because it derives directly from Component. Button's overall derivation is shown in Figure 28.1.
Listing 28.2. Public members of java.awt.Button.
public class Button extends Component {
public Button()
public Button(String label)
public synchronized void addNotify()
public String getLabel()
public void setLabel(String label)
}
Button | Button |
public Button()
This Button constructor constructs a simple button with no text label.
| Button | Button |
public Button(String label)
This Button constructor constructs a simple button with a text label.
Label is a String value used to set the button's label. |
addNotify | Button |
public synchronized void addNotify()
addNotify sets the peer of the button using the function getToolkit().createButton(). Using peer interfaces allows you to change the user interface of the button without changing its functionality.
addNotify() in class Component. |
getLabel | Button |
public String getLabel()
getLabel returns the button's label string.
A String value representing the button's label string. |
setLabel | Button |
public void setLabel(String label)
setLabel modifies the button's label string.
label is a String value representing the button's new label string. |
Canvas |
Component |
The class hierarchy for the Canvas class derives from the class java.awt.Component. (See Listing 28.3.) A Canvas is used as a drawing surface for GUI applications. Canvas's overall derivation is shown in Figure 28.1.
Listing 28.3. Public members of java.awt.Canvas.
public class Canvas extends Component {
public synchronized void addNotify()
public void paint(Graphics g)
}
addNotify | Canvas |
public synchronized void addNotify()
addNotify sets the peer of the Canvas using the function getToolkit().createCanvas(). Using peer interfaces allows you to change the user interface of the canvas without changing its functionality.
addNotify() in class Component. |
paint | Canvas |
public void paint(Graphics g)
The paint() method paints the Graphics canvas (specified by the g parameter) using the default background color, which is determined by calling getBackground().
paint() in class Component. |
CardLayout |
Object |
LayoutManager |
The class hierarchy for the CardLayout class derives from the class java.lang.Object. (See Listing 28.4.) The CardLayout class is a LayoutManager that allows the addition of cards, only one of which can be visible at any given time. The user is allowed to flip through the cards. CardLayout's overall derivation is shown in Figure 28.1.
Listing 28.4. Public members of java.awt.CardLayout.
public class CardLayout implements LayoutManager {
public CardLayout()
public CardLayout(int hgap, int vgap)
public void addLayoutComponent(String name, Component comp)
public void removeLayoutComponent(Component comp)
public Dimension preferredLayoutSize(Container target)
public Dimension minimumLayoutSize(Container target)
public void layoutContainer(Container parent)
public void first(Container parent)
public void next(Container parent)
public void previous(Container parent)
public void last(Container parent)
public void show(Container parent, String name)
public String toString()
}
CardLayout | CardLayout |
public CardLayout()
This CardLayout constructor creates a new CardLayout layout manager.
| CardLayout | CardLayout |
public CardLayout(int hgap, int vgap)
This CardLayout constructor constructs a CardLayout layout manager using the hgap and vgap values to set the horizontal and vertical gap sizes.
Hgap is an integer value used to set the horizontal gap size. |
| vgap is an integer value used to set the vertical gap size. |
addLayoutComponent | CardLayout |
public void addLayoutComponent(String name, Component comp)
name is a string value that corresponds to the component's name. |
| comp is a component object to be added to this layout manager. |
removeLayoutComponent | CardLayout |
public void removeLayoutComponent(Component comp)
removeLayoutComponent removes the specified component from the layout manager.
comp is the component object to be removed. |
minimumLayoutSize | CardLayout |
public Dimension minimumLayoutSize(Container target)
minimumLayoutSize returns the minimum Dimension needed to lay out the components contained in the target parameter. Note that this function only determines the required size based on visible components.
target is a Container class containing components to be laid out. This class could be a Frame, Window, or any other class derived from the Container class. |
preferredLayoutSize | CardLayout |
public Dimension preferredLayoutSize(Container target)
preferredLayoutSize returns the preferred Dimension needed to lay out the components contained in the target parameter. This Dimension is based on the individual component's preferred sizes. Note that this function only determines the required size based on visible components.
target is a Container class containing components to be laid out. This class could be a Frame, Window, or any other class derived from the Container class. |
layoutContainer | CardLayout |
public void layoutContainer(Container parent)
layoutContainer lays out the components contained in the parent Container parameter. This method reshapes the components in the Container based on the requirements of the BorderLayout itself.
parent is a Container class containing components to be laid out. This class could be a Frame, Window, or any other class derived from the Container class. |
first | CardLayout |
public void first(Container parent)
The first() method shows the first component in CardLayout (the first card).
parent is the parent Container class containing the components to be flipped through. |
next | CardLayout |
public void next(Container parent)
The next() method shows the next component in CardLayout (the next card).
parent is the parent Container class containing the components to be flipped through. |
previous | CardLayout |
public void previous(Container parent)
The previous() method shows the previous component in CardLayout (the previous card).
parent is the parent Container class containing the components to be flipped through. |
last | CardLayout |
public void last(Container parent)
The last() method shows the last component in CardLayout (the last card).
parent is the parent Container class containing the components to be flipped through. |
show | CardLayout |
public void show(Container parent, String name)
The show() method flips to the component specified in the name parameter.
parent is the parent Container class containing the components to be flipped through. |
| name is a string value representing the name of the component to be displayed. |
toString | CardLayout |
public String toString()
toString returns a string representation of the CardLayout class.
A String value containing the CardLayout class's name plus its hgap and vgap values (see the CardLayout() constructor). |
| toString() in class Object. |
Checkbox |
Component |
The class hierarchy for the Checkbox class derives from the class java.awt.Component. (See Listing 28.5.) A Checkbox is a user interface component that represents a true/false (or on/off) value. Checkbox's overall derivation is shown in Figure 28.1.
Listing 28.5. Public members of java.awt.Checkbox.
public class Checkbox extends Component {
public Checkbox()
public Checkbox(String label)
public Checkbox(String label, CheckboxGroup group, boolean state)
public synchronized void addNotify()
public String getLabel()
public void setLabel(String label)
public boolean getState()
public void setState(boolean state)
public CheckboxGroup getCheckboxGroup()
public void setCheckboxGroup(CheckboxGroup g)
}
Checkbox | Checkbox |
public Checkbox()
This Checkbox constructor
constructs the simplest of all checkboxes: one with no label,
no group, and a false state value.
Checkbox | Checkbox |
public Checkbox(String label)
This Checkbox constructor constructs a checkbox using the label parameter to set the checkbox's label. This checkbox belongs to no group and is set to a false state value.
label is a string value representing the Checkbox's label. |
Checkbox | Checkbox |
public Checkbox(String label, CheckboxGroup group, boolean state)
This Checkbox constructor constructs a checkbox including the label, group, and initial value.
label is a string value representing the Checkbox's label. |
| group is a CheckboxGroup object that this Checkbox is a member of. (For more information on CheckboxGroups, see the documentation for the CheckboxGroup class later in this chapter.) |
state is the initial state value for this Checkbox. |
addNotify | Checkbox |
public synchronized void addNotify()
addNotify sets the peer of the Checkbox using the function getToolkit().createCheckbox(). Using peer interfaces allows you to change the user interface of the Checkbox without changing its functionality.
addNotify() in class Component. |
getLabel | Checkbox |
public String getLabel()
getLabel returns the Checkbox's label string.
A String value representing the Checkbox's label string. |
setLabel | Checkbox |
public void setLabel(String label)
setLabel modifies the Checkbox's label string.
label is a String value representing the Checkbox's new label string. |
getState | Checkbox |
public boolean getState()
getState returns the Checkbox's current state value.
A Boolean value representing the Checkbox's current state. |
setState | Checkbox |
public void setState(boolean state)
setState sets the Checkbox to the value represented by the state parameter.
state is a Boolean value containing the new value of the Checkbox's state. |
getCheckboxGroup | Checkbox |
public CheckboxGroup getCheckboxGroup()
The getCheckboxGroup() method returns the CheckboxGroup that this Checkbox is a member of.
A CheckboxGroup class that this Checkbox is a member of. (For more information on CheckboxGroups, see the documentation for the CheckboxGroup class later in this chapter.) |
setCheckboxGroup | Checkbox |
public void setCheckboxGroup(CheckboxGroup g)
The setCheckboxGroup() method adds this Checkbox to a CheckboxGroup.
g is a CheckboxGroup class that this Checkbox is to be added to. (For more information on CheckboxGroups, see the documentation for the CheckboxGroup class later in this chapter.) |
CheckboxGroup |
Object |
The class hierarchy for the CheckboxGroup class derives from the class java.lang.Object. (See Listing 28.6.) A CheckboxGroup groups a set of Checkbox classes. When Checkboxes are created within a CheckboxGroup, only one Checkbox can be selected at one time. CheckboxGroup's overall derivation is shown in Figure 28.1.
Listing 28.6. Public members of java.awt.CheckboxGroup.
public class CheckboxGroup {
public CheckboxGroup()
public Checkbox getCurrent()
public synchronized void setCurrent(Checkbox box)
public String toString()
}
CheckboxGroup | CheckboxGroup |
public CheckboxGroup()
This CheckboxGroup constructor constructs a CheckboxGroup instance with no checkbox members.
| getCurrent | CheckboxGroup |
public Checkbox getCurrent()
The getCurrent() method returns the current Checkbox.
A Checkbox object representing the currently selected Checkbox. |
setCurrent | CheckboxGroup |
public synchronized void setCurrent(Checkbox box)
The setCurrent() method sets the current Checkbox in this CheckboxGroup.
box is the Checkbox object that is to be made current. |
toString | CheckboxGroup |
public String toString()
toString() returns a string containing CheckboxGroup information.
A String value containing the CheckboxGroup's name as well as the name of the currently selected Checkbox. |
| toString() in class Object. |
CheckboxMenuItem |
MenuItem |
The class hierarchy for the CheckboxMenuItem class derives from the class java.awt.MenuItem. (See Listing 28.7.) A CheckboxMenuItem is a user interface component that can be added to a menu to represent a Boolean value selection. CheckboxMenuItem's overall derivation is shown in Figure 28.1.
Listing 28.7. Public members of java.awt.CheckboxMenuItem.
public class CheckboxMenuItem extends MenuItem {
public CheckboxMenuItem(String label)
public synchronized void addNotify()
public boolean getState()
public void setState(boolean t)
public String paramString()
}
CheckboxMenuItem | CheckboxMenuItem |
public CheckboxMenuItem(String label)
This CheckboxMenuItem constructor creates a CheckboxMenuItem with a text label containing the string passed in.
label is a string value representing the label of the CheckboxMenuItem to be displayed. |
addNotify | CheckboxMenuItem |
public synchronized void addNotify()
addNotify sets the peer of the CheckboxMenuItem using the function getToolkit(). createCheckboxMenuItem(). Using peer interfaces allows you to change the user interface of the CheckboxMenuItem without changing its functionality.
addNotify() in class Component. |
getState | CheckboxMenuItem |
public boolean getState()
getState() returns the state value of the CheckboxMenuItem's checkbox.
A Boolean value representing the CheckboxMenuItem's checkbox state value. |
setState | CheckboxMenuItem |
public void setState(boolean t)
setState() sets the CheckboxMenuItem's checkbox state value.
t is a Boolean value representing the CheckboxMenuItem's checkbox state value. |
paramString | CheckboxMenuItem |
public String paramString()
paramString() returns a string containing CheckboxMenuItem information.
A string value containing the CheckboxMenuItem's label as well as the state value of the CheckboxMenuItem's checkbox. |
| paramString() in class MenuItem. |
Choice |
Component |
The class hierarchy for the Choice class derives from the class java.awt.Component. (See Listing 28.8.) A Choice is a user interface component that displays a pop-up menu. The current selection is displayed as the pop-up menu's title. Choice's overall derivation is shown in Figure 28.1.
Listing 28.8. Public members of java.awt.Choice.
public class Choice extends Component {
public Choice()
public synchronized void addNotify()
public int countItems()
public String getItem(int index)
public synchronized void addItem(String item)
public String getSelectedItem()
public int getSelectedIndex()
public synchronized void select(int pos)
public void select(String str)
}
Choice | Choice |
public Choice()
This Choice constructor creates a default Choice object that contains no information.
| addNotify | Choice |
public synchronized void addNotify()
addNotify sets the peer of the Choice using the function getToolkit().createChoice(). Using peer interfaces allows you to change the user interface of the Choice without changing its functionality.
addNotify() in class Component. |
countItems | Choice |
public int countItems()
countItems() returns the number of items (or choices) that are available in this Choice object. See the addItem() method later in this section for information on Choice items.
An integer value containing the number of items stored in this Choice object. |
getItem | Choice |
public String getItem(int index)
The getItem() method returns the choice string at the index represented by the index value passed in.
index is an integer value representing the index of the string item to be returned. |
| A String value representing the string at the index passed into this method. See the addItem() method for information on Choice items. |
addItem | Choice |
public synchronized void addItem(String item)
addItem() adds a String to a Choice object's internal list. The currently selected item in that list is displayed in the Choice object's pop-up menu.
item is a String object containing a string to be added to the choice list. |
| A NullPointerException if the string item to be added is null. |
getSelectedItem | Choice |
public String getSelectedItem()
getSelectedItem() returns the string value of the currently selected item. See the select() method later in this section for information on selecting Choice items.
A String value containing the currently selected item's string. |
getSelectedIndex | Choice |
public int getSelectedIndex()
getSelectedIndex() returns the index of the currently selected item. See the select() method for information on selecting Choice items.
An integer value containing the index of the currently selected item. |
select | Choice |
public synchronized void select(int pos)
This select() method selects the item at the position represented by the pos parameter.
pos is an integer value representing the position of the item to be selected. |
| An IllegalArgumentException if the position value passed in is invalid. |
select | Choice |
public void select(String str)
This select() method selects the item represented by the str parameter.
str is a String value representing the string value of the choice to be selected. |
Color |
Object |
The class hierarchy for the Color class derives from the class java.awt.Object. (See Listing 28.9.) The Color 1 class is provided to encapsulate RGB (Red-Green-Blue) color values. Color's overall derivation is shown in Figure 28.1.
Listing 28.9. Public members of java.awt.Color.
public final class Color {
public final static Color white
public final static Color lightGray
public final static Color gray
public final static Color darkGray
public final static Color black
public final static Color red
public final static Color pink
public final static Color orange
public final static Color yellow
public final static Color green
public final static Color magenta
public final static Color cyan
public final static Color blue
public Color(int r, int g, int b)
public Color(int rgb)
public Color(float r, float g, float b)
public int getRed()
public int getGreen()
public int getBlue()
public int getRGB()
public Color brighter()
public Color darker()
public int hashCode()
public boolean equals(Object obj)
public String toString()
public static Color getColor(String nm)
public static Color getColor(String nm, Color v)
public static Color getColor(String nm, int v)
public static int HSBtoRGB(float hue, float saturation, float brightness)
public static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals)
public static Color getHSBColor(float h, float s, float b)
}
Public Static Values |
public final static Color white
Static value representing the color white.
public final static Color lightGray
Static value representing the color light gray.
public final static Color gray
Static value representing the color gray.
public final static Color darkGray
Static value representing the color dark gray.
public final static Color black
Static value representing the color black.
public final static Color red
Static value representing the color red.
public final static Color pink
Static value representing the color pink.
public final static Color orange
Static value representing the color orange.
public final static Color yellow
Static value representing the color yellow.
public final static Color green
Static value representing the color green.
public final static Color magenta
Static value representing the color magenta.
public final static Color cyan
Static value representing the color cyan.
public final static Color blue
Static value representing the color blue.
| Color | Color |
public Color(int r, int g, int b)
This Color constructor accepts as arguments individual red, green, and blue color values. These values must be in the range 0-255 and are used to build a 24-bit color value using the following method:
The red value represents bits 16-23.
The green value represents bits 8-15.
The blue value represents bits 0-7.
This Color constructor determines the closest color to the value supported by the current output device.
r is the red color value. |
| g is the green color value. |
| b is the blue color value. |
Color | Color |
public Color(int rgb)
This Color constructor creates a Color object based on the RGB color value passed in.
rgb is an integer value containing the red, green, and blue color values that are used to create this Color object. |
Color | Color |
public Color(float r, float g, float b)
This Color constructor creates a Color object based on the color values passed in. This constructor is similar to the Color constructor that accepts integer red, green, and blue inputs except that this Color constructor accepts float values. These values must be in the range 0-1.0 and are used to build a 24-bit color value using the following method:
The red value * 255 represents bits 16-23.
The green value * 255 represents bits 8-15.
The blue value * 255 represents bits 0-7.
This Color constructor determines the closest color to the value supported by the current output device.
r is the red color value. |
| g is the green color value. |
| b is the blue color value. |
getRed | Color |
public int getRed()
The getRed() method returns the red component of this Color.
An integer value representing this Color's red component. |
getGreen | Color |
public int getGreen()
The getGreen() method returns the green component of this Color.
An integer value representing this Color's green component. |
getBlue | Color |
public int getBlue()
The getBlue() method returns the blue component of this Color.
An integer value representing this Color's blue component. |
getRGB | Color |
public int getRGB()
The getRGB() method returns the RGB value of this Color.
An integer value representing this Color's RGB value in the default RGB color model. |
brighter | Color |
public Color brighter()
The brighter() method brightens this Color by modifying the RGB color value. This method increases the individual red, green, and blue color components by a factor of approxi- mately 1.4.
A Color object representing a brighter version of the current color. |
darker | Color |
public Color darker()
The darker() method darkens this Color by modifying the RGB color value. This method decreases the individual red, green, and blue color components by a factor of approxi- mately 1.4.
A Color object representing a darker version of the current color. |
hashCode | Color |
public int hashCode()
hashCode() returns this Color's hash code. This is useful when storing Colors in a hash table.
An integer value representing this Color's hash code. |
| hashCode() in class Object. |
equals | Color |
public boolean equals(Object obj)
The equals() method compares the Object parameter with this Color object. It returns a Boolean value representing the result of this comparison.
obj is an Object object to be compared with this Color. |
| A Boolean value representing the result of the comparison of the Object parameter to this Color. |
| equals() in class Object. |
toString | Color |
public String toString()
toString()returns a string representation of the Color class.
A String value containing the Color class's name plus its red, green, and blue values (see the Color() constructors). |
| toString() in class Object. |
getColor | Color |
public static Color getColor(String nm)
getColor() returns the specified color property based on the name that is passed in.
nm is the name of the color property. |
| A Color value representing the desired color property. |
getColor | Color |
public static Color getColor(String nm, Color v)
getColor() returns the specified Color property of the specified color.
nm is the name of the color property. |
| v is the specified color to be examined. |
| A Color value representing the desired color property. |
getColor | Color |
public static Color getColor(String nm, int v)
getColor() returns the specified Color property of the color value that is passed in.
nm is the name of the color property. |
| v is the color value. |
| A Color value representing the desired color property. |
HSBtoRGB | Color |
public static int HSBtoRGB(float hue, float saturation, float brightness)
HSB stands for hue, saturation, and brightness. To convert from an HSB value to an RGB value, simply call this function with the appropriate arguments.
hue is the color's hue component. |
| saturation is the color's saturation component. |
| brightness is the color's brightness component. |
| An RGB value that corresponds to the HSB inputs. |
RGBtoHSB | Color |
public static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals)
HSB stands for hue, saturation, and brightness. To convert from an RGB value to an HSB value, simply call this function with the appropriate arguments.
r is the color's red component. |
| g is the color's green component. |
| b is the color's blue component. |
hsbvals is an array that stores the HSB result values.
| An array containing the resultant HSB values. |
getHSBColor | Color |
public static Color getHSBColor(float h, float s, float b)
The getHSBColor() method returns a Color object representing the RGB value of the input HSB parameters.
h is the color's hue component. |
| s is the color's saturation component. |
| b is the color's brightness component. |
| A Color object representing the RGB value of the input hue, saturation, and brightness. |
Component |
Object |
ImageObserver |
The class hierarchy for the Component class derives from the class java.lang.Object. (See Listing 28.10.) The Component class represents a generic user interface component. All AWT UI components derive from the Component class. Component's overall derivation is shown in Fig-ure 28.1.
Listing 28.10. Public members of java.awt.Component.
public abstract class Component implements ImageObserver {
public Container getParent()
public ComponentPeer getPeer()
public Toolkit getToolkit()
public boolean isValid()
public boolean isVisible()
public boolean isShowing()
public boolean isEnabled()
public Point location()
public Dimension size()
public Rectangle bounds()
public synchronized void enable()
public void enable(boolean cond)
public synchronized void disable()
public synchronized void show()
public void show(boolean cond)
public synchronized void hide()
public Color getForeground()
public synchronized void setForeground(Color c)
public Color getBackground()
public synchronized void setBackground(Color c)
public Font getFont()
public synchronized void setFont(Font f)
public synchronized ColorModel getColorModel()
public void move(int x, int y)
public void resize(int width, int height)
public void resize(Dimension d)
public synchronized void reshape(int x, int y, int width, int height)
public Dimension preferredSize()
public Dimension minimumSize()
public void layout()
public void validate()
public void invalidate()
public Graphics getGraphics()
public FontMetrics getFontMetrics(Font font)
public void paint(Graphics g)
public void update(Graphics g)
public void paintAll(Graphics g)
public void repaint()
public void repaint(long tm)
public void repaint(int x, int y, int width, int height)
public void repaint(long tm, int x, int y, int width, int height)
public void print(Graphics g)
public void printAll(Graphics g)
public boolean imageUpdate(Image img, int flags,
int x, int y, int w, int h)
public Image createImage(ImageProducer producer)
public Image createImage(int width, int height
public boolean prepareImage(Image image, ImageObserver observer)
public boolean prepareImage(Image image, int width, int height,
ImageObserver observer)
public int checkImage(Image image, ImageObserver observer)
public int checkImage(Image image, int width, int height,
ImageObserver observer)
public synchronized boolean inside(int x, int y)
public Component locate(int x, int y)
public void deliverEvent(Event e)
public boolean postEvent(Event e)
public boolean handleEvent(Event evt)
public boolean mouseDown(Event evt, int x, int y)
public boolean mouseDrag(Event evt, int x, int y)
public boolean mouseUp(Event evt, int x, int y)
public boolean mouseMove(Event evt, int x, int y)
public boolean mouseEnter(Event evt, int x, int y)
public boolean mouseExit(Event evt, int x, int y)
public boolean keyDown(Event evt, int key)
public boolean keyUp(Event evt, int key)
public boolean action(Event evt, Object what)
public void addNotify()
public synchronized void removeNotify()
public boolean gotFocus(Event evt, Object what)
public boolean lostFocus(Event evt, Object what)
public void requestFocus()
public void nextFocus()
public String toString()
public void list()
public void list(PrintStream out)
public void list(PrintStream out, int indent)
}
getParent | Component |
public Container getParent()
getParent() returns this component's parent (a Container class).
A Container class representing the component's parent. For more information on Containers, see the documentation for the Container class later in this chapter. |
GetPeer | Component |
public ComponentPeer getPeer()
getPeer() returns this component's peer (a ComponentPeer interface).
A ComponentPeer interface representing the component's peer. For more information on ComponentPeers, see the documentation for the ComponentPeer interface later in this chapter. |
getToolkit | Component |
public Toolkit getToolkit()
getToolkit() returns the toolkit of this component. The toolkit creates the peer for the component.
A Toolkit class. A toolkit is required to bind the abstract AWT classes to a native toolkit implementation. For more information on the Toolkit class, see the documentation for the Toolkit class later in this chapter. |
isValid | Component |
public boolean isValid()
isValid() determines whether this component is valid. A Component is considered to be invalid when it is first shown on the screen.
A Boolean value representing the valid state of this component. |
isVisible | Component |
public boolean isVisible()
isVisible() determines whether this component is visible. A Component is by default visible until told otherwise. A Component can be visible yet not show on the screen if the component's container is invisible.
A Boolean value representing the visible state of this component. |
isShowing | Component |
public boolean isShowing()
isShowing() determines whether this component is shown on the screen. A Component can be visible yet not show on the screen if the component's container is invisible.
A Boolean value representing the show state of this component. |
isEnabled | Component |
public boolean isEnabled()
isEnabled() determines whether this component is currently enabled. By default, components are enabled until told otherwise.
A Boolean value representing the enabled state of this component. |
location | Component |
public Point location()
location() returns the location of this component in its parent's coordinate space. Note that the Point object returned contains the top-left corner coordinates of this component.
A Point object containing the location of the component. |
size | Component |
public Dimension size()
size() returns the current size of the component.
A Dimension object containing the size of the component. |
bounds | Component |
public Rectangle bounds()
bounds() returns the bounding rectangle of the component.
A Rectangle object containing the boundaries for the component. |
enable | Component |
public synchronized void enable()
The enable() method enables a component. When a component is disabled, it might be grayed out or simply not respond to user input.
| enable | Component |
public void enable(boolean cond)
This enable() method conditionally enables a component. When a component is disabled, it might be grayed out or simply not respond to user inputs.
cond is a Boolean value representing the new enabled state of the component. |
disable | Component |
public synchronized void disable()
The disable() method disables a component. When a component is disabled, it might be grayed out or simply not respond to user inputs.
| show | Component |
public synchronized void show()
show() shows the component.
| show | Component |
public void show(boolean cond)
This show() method conditionally shows the component. If the input parameter is true, the component is shown. If the input parameter is false, the component is hidden.
cond is a Boolean value representing the new visible state of the component. |
hide | Component |
public synchronized void hide()
The hide() method hides the component from view.
| getForeground | Component |
public Color getForeground()
getForeground() returns the foreground color of the component. If the component's foreground color has not been set, the foreground color of its parent is returned.
A Color object representing the foreground color of this component. |
setForeground | Component |
public synchronized void setForeground(Color c)
setForeground() sets the foreground color of the component.
c is the new foreground color of this component. |
getBackground | Component |
public Color getBackground()
getBackground() returns the background color of the component. If the component's background color has not been set, the background color of its parent is returned.
A Color object representing the background color of this component. |
setBackground | Component |
public synchronized void setBackground(Color c)
setBackground() sets the background color of the component.
c is the new background color of this component. |
getFont | Component |
public Font getFont()
getFont() returns the font of the component. If the component's font has not been set, the font of its parent is returned.
| setFont | Component |
public synchronized void setFont(Font f)
setFont() sets the font of the component.
f is the new font of this component |
getColorModel | Component |
public synchronized ColorModel getColorModel()
getColorModel() gets the color model that displays this component on an output device.
A ColorModel object representing the color model used by this component. |
move | Component |
public void move(int x, int y)
The move() method moves a component to a new location within its parent's coordinate space.
x is the new x coordinate of the component within its parent's coordinate space. |
| y is the new y coordinate of the component within its parent's coordinate space. |
resize | Component |
public void resize(int width, int height)
resize() resizes the component to the specified width and height.
width is the new width size of the component. |
| height is the new height size of the component. |
resize | Component |
public void resize(Dimension d)
resize() resizes the component to the specified dimension.
d is a Dimension object representing the new size of the component. |
reshape | Component |
public synchronized void reshape(int x, int y, int width, int height)
reshape() completely changes the bounding box of the component by changing its size and location.
x is the new x coordinate of the component within its parent's coordinate space. |
| y is the new y coordinate of the component within its parent's coordinate space. |
| width is the new width size of the component. |
| height is the new height size of the component. |
preferredSize | Component |
public Dimension preferredSize()
The preferredSize() method returns the preferred size of the component.
A Dimension object representing the preferred size of the component. |
minimumSize | Component |
public Dimension minimumSize()
minimumSize() returns the minimum size of the component.
A Dimension object representing the minimum size of the component. |
layout | Component |
public void layout()
The layout() method is called when the component needs to be laid out.
| validate | Component |
public void validate()
validate() validates a component by calling its layout() method.
| invalidate | Component |
public void invalidate()
invalidate() invalidates a component, forcing the component and all parents above it to be laid out.
| getGraphics | Component |
public Graphics getGraphics()
getGraphics() returns a Graphics context for the component. If the component is not currently on the screen, this function returns null.
A Graphics object representing the component's graphics context. |
getFontMetrics | Component |
public FontMetrics getFontMetrics(Font font)
getFontMetrics() returns the current FontMetrics for a specified font. If the component is not currently on the screen, this function returns null.
font is a Font object to be examined. |
| A FontMetrics object representing the component's FontMetrics. |
paint | Component |
public void paint(Graphics g)
The paint() method paints the component on the screen using the Graphics context parameter.
g is the Graphics context that the component paints itself onto. |
update | Component |
public void update(Graphics g)
The update() method repaints the component in response to a call to the repaint() method. For more information on the repaint() method, see the documentation later in this chapter.
g is the Graphics context that the component paints itself onto. |
paintAll | Component |
public void paintAll(Graphics g)
The paintAll() method paints the component along with all its subcomponents.
g is the Graphics context that the component paints itself onto. |
repaint | Component |
public void repaint()
repaint() forces a component to repaint itself. Calling this function results in a call to update(). For more information on the update() method, see the documentation earlier in this chapter.
| repaint | Component |
public void repaint(long tm)
This repaint() method forces a component to repaint itself in tm milliseconds.
tm is the time, in milliseconds, that the component has to repaint itself from the time this method is called. |
repaint | Component |
public void repaint(int x, int y, int width, int height)
This repaint() method forces the component to repaint part of its surface area based on the input coordinates.
x is the x coordinate marking the surface area to be repainted. |
| y is the y coordinate marking the surface area to be repainted. |
| width is the width of the surface area to be repainted. |
| height is the height of the surface area to be repainted. |
repaint | Component |
public void repaint(long tm, int x, int y, int width, int height)
This repaint() method forces the component to repaint part of its surface area based on the input coordinates at a specified time in the future.
tm is the time, in milliseconds, from the time this method is called that the component has to repaint itself. |
| x is the x coordinate marking the surface area to be repainted. |
| y is the y coordinate marking the surface area to be repainted. |
| width is the width of the surface area to be repainted. |
| height is the height of the surface area to be repainted. |
Component |
public void print(Graphics g)
print() prints the component using the Graphics context. The default implementation of this method calls paint().
g is the Graphics context to be printed on. |
printAll | Component |
public void printAll(Graphics g)
printAll() prints the component and all of its subcomponents using the Graphics context.
g is the Graphics context to be printed on. |
imageUpdate | Component |
public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h)
imageUpdate() repaints the component when the specified image has changed. |
| img is an Image object to be examined for changes. |
| flags contains imaging flags such as FRAMEBITS, ALLBITS, and SOMEBITS (see documentation for the ImageObserver interface later in this chapter). |
| x is the x coordinate marking the surface area to be repainted. |
| y is the y coordinate marking the surface area to be repainted. |
| width is the width of the surface area to be repainted. |
| height is the height of the surface area to be repainted. |
| A Boolean value that is true if the image has changed, false if it hasn't. |
createImage | Component |
public Image createImage(ImageProducer producer)
createImage() creates an Image using the specified ImageProducer.
producer is an ImageProducer interface that produces a new image. |
| An Image object. |
createImage | Component |
public Image createImage(int width, int height)
This createImage() creates an off-screen image object using the specified width and height. This image object can be used for things like double-buffering.
width is the width of the Image object to be created. |
| height is the height of the Image object to be created. |
| An Image object. |
prepareImage | Component |
public boolean prepareImage(Image image, ImageObserver observer)
prepareImage() prepares an Image for rendering on this component. Because the Image is downloaded using a separate thread, the ImageObserver interface is notified when the Image is ready to be rendered.
image is an Image object that is rendered on this component. |
| observer is an Observer interface that is notified when the Image is ready to be rendered. |
| A Boolean value that is true if the Image has been prepared, false if it hasn't. |
prepareImage | Component |
public boolean prepareImage(Image image, int width, int height, ImageObserver Âobserver)
This prepareImage() method is similar to the prepareImage() method documented previously except that this method scales the Image based on the width and height parameters.
image is an Image object that is rendered on this component. |
| width is the width of the image to be rendered. |
| height is the height of the image to be rendered. |
| observer is an Observer interface that is notified when the Image is ready to be rendered. |
| A Boolean value that is true if the Image has been prepared, false if it hasn't. |
checkImage | Component |
public int checkImage(Image image, ImageObserver observer)
checkImage() checks the status of the construction of the Image to be rendered.
image is an Image object that is rendered on this component. |
| observer is an Observer interface that is notified when the Image is ready to be rendered. |
| An integer value that is the Boolean OR of the ImageObserver flags for the data that is currently available (see the documentation for the ImageObserver interface later in this chapter). |
checkImage | Component |
public int checkImage(Image image, int width, int height, ImageObserver Âobserver)
This checkImage() method checks the status of the construction of a scaled representation of this image.
image is an Image object that is rendered on this component. |
| width is the width of the image to be checked. |
| height is the height of the image to be checked. |
| observer is an Observer interface that is notified when the Image is ready to be rendered. |
| An integer value that is the Boolean OR of the ImageObserver flags for the data that is currently available (see the documentation for the ImageObserver interface later in this chapter). |
inside | Component |
public synchronized boolean inside(int x, int y)
The inside() method determines whether the x and y coordinates are within the bounding rectangle of the component.
x is the x coordinate to be examined. |
| y is the y coordinate to be examined. |
| A Boolean value representing the result of the coordinates check. |
locate | Component |
public Component locate(int x, int y)
locate() returns the Component at the specified x and y coordinates.
x is the x coordinate to be examined. |
| y is the y coordinate to be examined. |
| The Component that is found at the specified x and y coordinates. |
deliverEvent | Component |
public void deliverEvent(Event e)
The deliverEvent() delivers an event to the component or one of its subcomponents.
e is an Event object encapsulating the event. |
postEvent | Component |
public boolean postEvent(Event e)
postEvent() posts an event to the component resulting in a call to handleEvent().
e is an Event object encapsulating the event. |
| A Boolean value that is true if the event was handled and false if it wasn't. |
handleEvent | Component |
public boolean handleEvent(Event evt)
handleEvent() handles individual events by the component.
evt is an Event object encapsulating the event. |
| A Boolean value that is true if the event was handled and false if it wasn't. |
mouseDown | Component |
public boolean mouseDown(Event evt, int x, int y)
The mouseDown() method is called if the mouse is down.
evt is an Event object encapsulating the event. |
| x is the x coordinate of the mouse-down click point. |
| y is the y coordinate of the mouse-down click point. |
| A Boolean value that is true if the event was handled and false if it wasn't. |
mouseDrag | Component |
public boolean mouseDrag(Event evt, int x, int y)
The mouseDrag() method is called if the mouse is dragged.
evt is an Event object encapsulating the event. |
| x is the x coordinate of the current mouse point coordinate. |
| y is the y coordinate of the current mouse point coordinate. |
| A Boolean value that is true if the event was handled and false if it wasn't. |
mouseUp | Component |
public boolean mouseUp(Event evt, int x, int y)
The mouseUp() method is called when the mouse button is released.
evt is an Event object encapsulating the event. |
| x is the x coordinate of the mouse up point. |
| y is the y coordinate of the mouse up point. |
| A Boolean value that is true if the event was handled and false if it wasn't. |
mouseMove | Component |
public boolean mouseMove(Event evt, int x, int y)
The mouseMove() method is called if the mouse is moved.
evt is an Event object encapsulating the event. |
| x is the x coordinate of the current mouse point coordinate. |
| y is the y coordinate of the current mouse point coordinate. |
| A Boolean value that is true if the event was handled and false if it wasn't. |
mouseEnter | Component |
public boolean mouseEnter(Event evt, int x, int y)
The mouseEnter() method is called if the mouse enters the component.
evt is an Event object encapsulating the event. |
| x is the x coordinate of the current mouse point coordinate. |
| y is the y coordinate of the current mouse point coordinate. |
| A Boolean value that is true if the event was handled and false if it wasn't. |
mouseExit | Component |
public boolean mouseExit(Event evt, int x, int y)
The mouseExit() method is called if the mouse exits the component.
evt is an Event object encapsulating the event. |
| x is the x coordinate of the mouse exit point. |
| y is the y coordinate of the mouse exit point. |
| A Boolean value that is true if the event was handled and false if it wasn't. |
keyDown | Component |
public boolean keyDown(Event evt, int key)
The keyDown() method is called when a key is pressed.
evt is an Event object encapsulating the event. |
| key is an integer value representing the code of the key that was pressed. |
| A Boolean value that is true if the event was handled and false if it wasn't. |
keyUp | Component |
public boolean keyUp(Event evt, int key)
The keyUp() method is called when a key is released.
evt is an Event object encapsulating the event. |
| key is an integer value representing the code of the key that was pressed. |
| A Boolean value that is true if the event was handled and false if it wasn't. |
action | Component |
public boolean action(Event evt, Object what)
The action() method is called if an action occurs within the component. For more information on handling actions, see the handleEvent() method.
evt is an Event object encapsulating the event. |
| what is an object representing the action that is occurring. |
| A Boolean value that is true if the event was handled and false if it wasn't. |
addNotify | Component |
public void addNotify()
addNotify() notifies a component to create a peer object.
none |
removeNotify | Component |
public synchronized void removeNotify()
removeNotify() notifies a component to destroy the peer object.
none |
gotFocus | Component |
public boolean gotFocus(Event evt, Object what)
The gotFocus() method is called when the component receives the input focus.
evt is an Event object encapsulating the event. |
| what is an object representing the action that is occurring. |
| A Boolean value that is true if the event was handled and false if it wasn't. |
lostFocus | Component |
public boolean lostFocus(Event evt, Object what)
The lostFocus() method is called when the component loses the input focus.
evt is an Event object encapsulating the event. |
| what is an object representing the action that is occurring. |
| A Boolean value that is true if the event was handled and false if it wasn't. |
requestFocus | Component |
public void requestFocus()
The requestFocus() method requests the current input focus. If this method is successful, gotFocus() is then called.
none |
nextFocus | Component |
public void nextFocus()
The nextFocus() method switches the focus to the next component. The next component can be determined by examining the tab order of the components on a form.
none |
toString | Component |
public String toString()
toString returns a string representation of the Component class.
A String value containing the Component class's name plus its x, y, height, and width values (see the Component() constructors). |
| toString() in class Object. |
list | Component |
public void list()
The list() method prints a listing of the component to the print stream.
none |
list | Component |
public void list(PrintStream out)
This list() method prints a listing of the component to the specified output stream.
out is a PrintStream object. |
list | Component |
public void list(PrintStream out, int indent)
This list() method prints a listing of the component to the specified output stream at the specified indention.
out is a PrintStream object. |
| indent is an integer value representing the amount to be indented. |
Container |
Component |
The class hierarchy for the Container class derives from the class java.awt.Component. (See Listing 28.11.) A Container class is defined as a class that can contain other components. Container's overall derivation is shown in Figure 28.1.
Listing 28.11. Public members of java.awt.Container.
public abstract class Container extends Component {
public int countComponents()
public synchronized Component getComponent(int n)
Âthrows ArrayIndexOutOfBoundsException
public synchronized Component[] getComponents()
public Insets insets()
public Component add(Component comp)
public synchronized Component add(Component comp, int pos)
public synchronized Component add(String name, Component comp)
public synchronized void remove(Component comp)
public synchronized void removeAll()
public LayoutManager getLayout()
public void setLayout(LayoutManager mgr)
public synchronized void layout()
public synchronized void validate()
public synchronized Dimension preferredSize()
public synchronized Dimension minimumSize()
public void paintComponents(Graphics g)
public void printComponents(Graphics g)
public void deliverEvent(Event e)
public Component locate(int x, int y)
public synchronized void addNotify()
public synchronized void removeNotify()
public void list(PrintStream out, int indent)
}
countComponents | Container |
public int countComponents()
countComponents() returns the number of components contained within the container.
An integer value representing the number of components within the container. |
getComponent | Container |
public synchronized Component getComponent(int n)
The getComponent() method returns the component at the specified index.
n is an integer value representing the index of where to retrieve a component. |
| A Component object within the Container. |
| An ArrayIndexOutOfBoundsException if the component does not exist. |
getComponents | Container |
public synchronized Component[] getComponents()
getComponents() returns an array of Component objects contained within the Container.
An array of Components contained within the container. |
insets | Container |
public Insets insets()
The insets() method returns the borders of this container.
An Insets object representing the insets of the container. For more information, see the documentation for the Insets class later in this chapter. |
add | Container |
public Component add(Component comp)
The add() method adds a Component to the container at the end of the container's array of components.
comp is the component to be added. |
| The Component object that was added to the container's list. |
add | Container |
public synchronized Component add(Component comp, int pos)
This add() method adds a Component to the container at the specified index in the container's array of components.
comp is the component to be added. |
| pos is the position where the component is to be added. |
| The Component object that was added to the container's list. |
add | Container |
public synchronized Component add(String name, Component comp)
This add() method adds a component using the Component argument and that Component's name.
name is a String representing the name of the component. |
| comp is the component to be added. |
| The Component object that was added to the container's list. |
remove | Container |
public synchronized void remove(Component comp)
The remove() method removes the specified component from the Container's list.
comp is the component to be removed. |
removeAll | Container |
public synchronized void removeAll()
The removeAll() method removes all components within Container.
none |
getLayout | Container |
public LayoutManager getLayout()
getLayout() returns this Container's LayoutManager. For more information on the LayoutManager interface, see the LayoutManager documentation later in this chapter.
A LayoutManager interface representing the Container's LayoutManager. |
setLayout | Container |
public void setLayout(LayoutManager mgr)
setLayout() sets the current LayoutManager of the Container. For more information on the LayoutManager interface, see the LayoutManager documentation later in this chapter.
mgr is the LayoutManager that controls the layouts of this Container's components. |
layout | Container |
public synchronized void layout()
The layout() method is called to perform a layout on this component.
none |
validate | Container |
public synchronized void validate()
The validate() method refreshes the Container and all the components within it by validating the Container and all of its components.
none |
preferredSize | Container |
public synchronized Dimension preferredSize()
preferredSize() returns the preferred size of this Container.
A Dimension object representing the preferred size of this Container. For more information on the Dimension class, see the documentation later in this chapter. |
minimumSize | Container |
public synchronized Dimension minimumSize()
minimumSize() returns the minimum size of this Container.
A Dimension object representing the minimum size of this Container. For more information on the Dimension class, see the documentation later in this chapter. |
paintComponents | Container |
public void paintComponents(Graphics g)
The paintComponents() method paints each of the components within the container.
g is the Graphics context that the Container's components are painted on. |
printComponents | Container |
public void printComponents(Graphics g)
The printComponents() method prints each of the components within the container.
g is the Graphics context that the Container's components are printed on. |
deliverEvent | Container |
public void deliverEvent(Event e)
deliverEvent() locates the appropriate component within the container that the event applies to and delivers the event to that component.
e is the event to be delivered. |
locate | Container |
public Component locate(int x, int y)
The locate() method locates and returns the component that lies at the specified x and y coordinates within the container.
x is the x coordinate of the component to be located. |
| y is the y coordinate of the component to be located. |
addNotify | Container |
public synchronized void addNotify()
addNotify() notifies the container to create a peer interface. This method also notifies each of the container's components to do likewise.
none |
removeNotify | Container |
public synchronized void removeNotify()
removeNotify() notifies the container to remove its peer. This method also notifies each of the container's components to do likewise.
none |
list | Container |
public void list(PrintStream out, int indent)
The list() method prints a list for each component within the container to the specified output stream at the specified indentation.
out is a PrintStream object. |
| indent is an integer amount representing the value to indent the list. |
Dialog |
Window |
The class hierarchy for the Dialog class derives from the class java.awt.Window. (See Listing 28.12.) The Dialog class creates a window that can be closed by the user. Dialogs are usually temporary windows that are used for entering information. Dialog's overall derivation is shown in Figure 28.1.
Listing 28.12. Public members of java.awt.Dialog.
public class Dialog extends Window {
public Dialog(Frame parent, boolean modal)
public Dialog(Frame parent, String title, boolean modal)
public synchronized void addNotify()
public boolean isModal()
public String getTitle()
public void setTitle(String title)
public boolean isResizable()
public void setResizable(boolean resizable)
}
Dialog | Dialog |
public Dialog(Frame parent, boolean modal)
This Dialog() constructor constructs a Dialog object from a parent Frame object. This Dialog is initially invisible.
Parent is the parent frame of the Dialog. |
| Modal is a Boolean value designating this dialog to be either modal or nonmodal. If a dialog is modal, it blocks out all user input to other objects and retains the sole focus on the screen. |
Dialog | Dialog |
public Dialog(Frame parent, String title, boolean modal)
This Dialog() constructor constructs a Dialog object with a title from a parent Frame object. This Dialog is initially invisible.
Parent is the parent frame of the Dialog. |
| Title is a String value representing the title to be displayed for this Dialog. |
| Modal is a Boolean value designating this dialog to be either modal or nonmodal. If a dialog is modal, it blocks out all user input to other objects and retains the sole focus on the screen. |
AddNotify | Dialog |
public synchronized void addNotify()
The addNotify() method creates the Dialog's peer. Using a peer interface allows you to change the Dialog's appearance without changing its functionality.
| IsModal | Dialog |
public boolean isModal()
isModal() returns the modal status of the dialog.
A Boolean value representing the Dialog's modal status. If this is true, the dialog is modal. If false, the dialog is nonmodal. |
GetTitle | Dialog |
public String getTitle()
getTitle() returns the dialog's title string.
A String value representing the title string of the dialog. |
SetTitle | Dialog |
public void setTitle(String title)
The setTitle() method sets the Dialog's title string.
Title is a String value representing the Dialog's new title. |
IsResizable | Dialog |
public boolean isResizable()
The isResizable() method is called to determine whether this dialog can be resized.
A Boolean value that is true if the dialog is resizable and false if it is not. |
SetResizable | Dialog |
public void setResizable(boolean resizable)
The setResizable() method changes whether a dialog can be resized.
Resizable is a Boolean value that is true if the dialog is to be resizable and false if not. |
Dimension |
Object |
The class hierarchy for the Dimension class derives from the class java.lang.Object. (See Listing 28.13.) A Dimension class encapsulates an object's height and width. Dimension's overall derivation is shown in Figure 28.1.
Listing 28.13. Public members of java.awt.Dimension.
public class Dimension {
public int width;
public int height;
public Dimension()
public Dimension(Dimension d)
public Dimension(int width, int height)
public String toString()
}
Public Instance Variables |
public int width
The width instance variable contains the integer value representing the Dimension's width value.
public int height
The height instance variable contains the integer value representing the Dimension's height value.
| Dimension | Dimension |
public Dimension()
This Dimension() constructor constructs an empty Dimension object (zero width and zero height, by default).
| Dimension | Dimension |
public Dimension(Dimension d)
This Dimension() constructor constructs a Dimension object from an existing Dimension object.
d is a Dimension object whose values are used to create the new Dimension. |
Dimension | Dimension |
public Dimension(int width, int height)
This Dimension() constructor constructs a Dimension object based on the width and height input parameters.
width is an integer value representing the width of the new Dimension. |
| height is an integer value representing the height of the new Dimension. |
toString | Dimension |
public String toString()
The toString() method returns a String representation of this Dimension object.
A String containing this Dimension's height and width values. |
Event |
Object |
The class hierarchy for the Event class derives from the class java.lang.Object. (See Listing 28.14.) The Event class encapsulates GUI events in a platform-independent manner. Event's overall derivation is shown in Figure 28.1.
Listing 28.14. Public members of java.awt.Event.
public class Event {
public static final int SHIFT_MASK
public static final int CTRL_MASK
public static final int META_MASK
public static final int ALT_MASK
public static final int HOME
public static final int END
public static final int PGUP
public static final int PGDN
public static final int UP
public static final int DOWN
public static final int LEFT
public static final int RIGHT
public static final int f1
public static final int f2
public static final int f3
public static final int f4
public static final int f5
public static final int f6
public static final int f7
public static final int f8
public static final int f9
public static final int f10
public static final int f11
public static final int f12
public static final int WINDOW_DESTROY
public static final int WINDOW_EXPOSE
public static final int WINDOW_ICONIFY
public static final int WINDOW_DEICONIFY
public static final int WINDOW_MOVED
public static final int KEY_PRESS
public static final int KEY_RELEASE
public static final int KEY_ACTION
public static final int KEY_ACTION_RELEASE
public static final int MOUSE_DOWN
public static final int MOUSE_UP
public static final int MOUSE_MOVE
public static final int MOUSE_ENTER
public static final int MOUSE_EXIT
public static final int MOUSE_DRAG
public static final int SCROLL_LINE_UP
public static final int SCROLL_LINE_DOWN
public static final int SCROLL_PAGE_UP
public static final int SCROLL_PAGE_DOWN
public static final int SCROLL_ABSOLUTE
public static final int LIST_SELECT
public static final int LIST_DESELECT
public static final int ACTION_EVENT
public static final int LOAD_FILE
public static final int SAVE_FILE
public static final int GOT_FOCUS
public static final int LOST_FOCUS
public Object target;
public long when;
public int id;
public int x;
public int y;
public int key;
public int modifiers;
public int clickCount;
public Object arg;
public Event evt;
public Event(Object target, long when, int id, int x, int y, int key,
int modifiers, Object arg)
public Event(Object target, long when, int id, int x, int y, int key, int
Âmodifiers)
public Event(Object target, int id, Object arg)
public void translate(int x, int y)
public boolean shiftDown()
public boolean controlDown()
public boolean metaDown()
public String toString()
}
Public Static Values |
public static final int SHIFT_MASK
The SHIFT_MASK value represents the Shift Modifier constant.
public static final int CTRL_MASK
The CTRL_MASK value represents the Control Modifier constant.
public static final int META_MASK
The META_MASK value represents the Meta Modifier constant.
public static final int ALT_MASK
The ALT_MASK value represents the Alt Modifier constant.
public static final int HOME
The HOME value represents the Home key.
public static final int END
The END value represents the End key.
public static final int PGUP
The PGUP value represents the Page Up key.
public static final int PGDN
The PGDN value represents the Page Down key.
public static final int UP
The UP value represents the Up Arrow key.
public static final int DOWN
The DOWN value represents the Down Arrow key.
public static final int LEFT
The LEFT value represents the Left Arrow key.
public static final int RIGHT
The RIGHT value represents the Right Arrow key.
public static final int f1
The f1 value represents the f1 key.
public static final int f2
The f2 value represents the f2 key.
public static final int f3
The f3 value represents the f3 key.
public static final int f4
The f4 value represents the f4 key.
public static final int f5
The f5 value represents the f5 key.
public static final int f6
The f6 value represents the f6 key.
public static final int f7
The f7 value represents the f7 key.
public static final int f8
The f8 value represents the f8 key.
public static final int f9
The f9 value represents the f9 key.
public static final int f10
The f10 value represents the f10 key.
public static final int f11
The f11 value represents the f11 key.
public static final int f12
The f12 value represents the f12 key.
public static final int WINDOW_DESTROY
The WINDOW_DESTROY value represents the destroy window event.
public static final int WINDOW_EXPOSE
The WINDOW_EXPOSE value represents the expose window event.
public static final int WINDOW_ICONIFY
The WINDOW_ICONIFY value represents the iconify window event.
public static final int WINDOW_DEICONIFY
The DEICONIFY_WINDOW value represents the deiconify window event.
public static final int WINDOW_MOVED
The WINDOW_MOVED value represents the window moved event.
public static final int KEY_PRESS
The KEY_PRESS value represents the key press event.
public static final int KEY_RELEASE
The KEY_RELEASE value represents the key release event.
public static final int KEY_ACTION
The KEY_ACTION value represents the key action keyboard event.
public static final int KEY_ACTION_RELEASE
The KEY_ACTION_RELEASE value represents the key action release keyboard event.
public static final int MOUSE_DOWN
The MOUSE_DOWN value represents the mouse down event.
public static final int MOUSE_UP
The MOUSE_UP value represents the mouse up event.
public static final int MOUSE_MOVE
The MOUSE_MOVE value represents the mouse move event.
public static final int MOUSE_ENTER
The MOUSE_ENTER value represents the mouse enter event.
public static final int MOUSE_EXIT
The MOUSE_EXIT value represents the mouse exit event.
public static final int MOUSE_DRAG
The MOUSE_DRAG value represents the mouse drag event.
public static final int SCROLL_LINE_UP
The SCROLL_LINE_UP value represents the line up scroll event.
public static final int SCROLL_LINE_DOWN
The SCROLL_LINE_DOWN value represents the line down scroll event.
public static final int SCROLL_PAGE_UP
The SCROLL_PAGE_UP value represents the page up scroll event.
public static final int SCROLL_PAGE_DOWN
The SCROLL_PAGE_DOWN value represents the page down scroll event.
public static final int SCROLL_ABSOLUTE
The SCROLL_ABSOLUTE value represents the absolute scroll event.
public static final int LIST_SELECT
The LIST_SELECT value represents the select list event.
public static final int LIST_DESELECT
The LIST_DESELECT value represents the deselect list event.
public static final int ACTION_EVENT
The ACTION_EVENT value represents an action event.
public static final int LOAD_FILE
The LOAD_FILE value represents a file load event.
public static final int SAVE_FILE
The SAVE_FILE value represents a file save event.
public static final int GOT_FOCUS
The GOT_FOCUS value represents a got focus event.
public static final int LOST_FOCUS
The LOST_FOCUS value represents
a lost focus event.
Public Instance Variables |
public Object target
The target instance variable represents the object that is the target of the event.
public long when
The when instance variable represents the timestamp of the event.
public int id
The id instance variable represents the type of the event.
public int x
The x instance variable represents the x coordinate of the event.
public int y
The y instance variable represents the y coordinate of the event.
public int key
The key instance variable represents the key that was pressed to trigger the keyboard event (see the key values listed previously).
public int modifiers
The modifiers instance variable represents the state of the modifier keys.
public int clickCount
The clickCount instance variable represents the number of clicks during the mouse down event. If this event wasn't triggered by a mouse down action, this value is 0. It is 1 for a single click and 2 for a double click.
public Object arg
The arg instance variable represents an arbitrary argument.
public Event evt
The evt instance variable represents the next event. This is useful when multiple events are stored in an array or linked list.
| Event | Event |
public Event(Object target, long when, int id, int x, int y, int key,
 int modifiers, Object arg)
This Event()constructor constructs an event using the target, current time, event ID, location, key pressed, modifiers, and some argument.
target is the target object for the event. |
| when is the timestamp for the event. |
| id is the event type. |
| x is the x coordinate of the event. |
| y is the y coordinate of the event. |
| key is the key pressed that triggered a keyboard event. |
| modifiers is the state of the modifier keys. |
| arg is an arbitrary argument. |
Event | Event |
public Event(Object target, long when, int id, int x, int y,
 int key, int modifiers)
This Event() constructor constructs an event using the target, current time, event ID, location, key pressed, and modifiers.
target is the target object for the event. |
when is the timestamp for the event. |
| id is the event type. |
| x is the x coordinate of the event. |
| y is the y coordinate of the event. |
| key is the key pressed that triggered a keyboard event. |
| modifiers contains the state of the modifier keys. |
Event | Event |
public Event(Object target, int id, Object arg)
This Event() constructor constructs an event using the target, event ID, and some argument.
target is the target object for the event. |
| id is the event type. |
| arg is an arbitrary argument. |
translate | Event |
public void translate(int x, int y)
The translate() method translates coordinates for a given component. If the object sending this event has targeted a certain component, this method translates the coordinates to make sense for that particular component.
x is the x coordinate. |
| y is the y coordinate. |
shiftDown | Event |
public boolean shiftDown()
The shiftDown() method returns the current state of the Shift key.
A Boolean value that is true if the Shift key is down and false if it is up. |
controlDown | Event |
public boolean controlDown()
The controlDown() method returns the current state of the Control key.
A Boolean value that is true if the Control key is down and false if it is up. |
metaDown | Event |
public boolean metaDown()
The metaDown() method returns the current state of the Meta key.
A Boolean value that is true if the Meta key is down and false if it is up. |
toString | Event |
public String toString()
The toString() method returns the string representation of the current event.
A String value containing information on the event, including the id, x, y, key, shiftDown, controlDown, and metaDown values. |
FileDialog |
Dialog |
The class hierarchy for the FileDialog class derives from the class java.awt.Dialog. (See Listing 28.15.) A FileDialog is presented for a user to select a file. This dialog is a modal dialog; therefore, the calling thread is blocked until this dialog exits. FileDialog's overall derivation is shown in Figure 28.1.
Listing 28.15. Public members of java.awt.FileDialog.
public class FileDialog extends Dialog {
public static final int LOAD
public static final int SAVE
public FileDialog(Frame parent, String title)
public FileDialog(Frame parent, String title, int mode)
public synchronized void addNotify()
public int getMode()
public String getDirectory()
public void setDirectory(String dir)
public String getFile()
public void setFile(String file)
public void setFilenameFilter(FilenameFilter filter)
public FilenameFilter getFilenameFilter()
}
Public Static Values |
public static final int LOAD
The LOAD static value represents the file load variable.
public static final int SAVE
The SAVE static value represents the file save variable.
| FileDialog | FileDialog |
public FileDialog(Frame parent, String title)
This FileDialog() constructor constructs a file dialog using a parent frame and a title string.
Parent is the parent frame of the FileDialog. |
| Title is a String containing the dialog's title. |
FileDialog | FileDialog |
public FileDialog(Frame parent, String title, int mode)
This FileDialog() constructor constructs a file dialog using a parent frame, a title string, and a mode value representing either a LOAD or SAVE dialog.
Parent is the parent frame of the FileDialog. |
| Title is a String containing the dialog's title. |
| Mode is an integer value representing the dialog mode (LOAD or SAVE). |
AddNotify | FileDialog |
public synchronized void addNotify()
addNotify() notifies the FileDialog to create a peer. Using a peer interface allows you to change the user interface of the FileDialog without changing its functionality.
None |
getMode | FileDialog |
public int getMode()
getMode() returns the current mode of the FileDialog.
An integer value representing the current mode (LOAD or SAVE) of the FileDialog. |
GetDirectory | FileDialog |
public String getDirectory()
The getDirectory() method returns the current directory of the FileDialog.
A String value representing the FileDialog's current directory. |
SetDirectory | FileDialog |
public void setDirectory(String dir)
The setDirectory() method sets the current directory of the FileDialog.
Dir is a String value representing the directory to be set. |
GetFile | FileDialog |
public String getFile()
The getFile() method returns the currently selected file within the FileDialog.
A String value representing the FileDialog's current file. |
SetFile | FileDialog |
public void setFile(String file)
The setFile() method sets the current file of the FileDialog.
file is a String value representing the file to be set. |
setFilenameFilter | FileDialog |
public void setFilenameFilter(FilenameFilter filter)
The setFilenameFilter() method sets the file filter for the FileDialog to the specified FilenameFilter.
filter is a FilenameFilter representing the filter to be set. For more information on the FilenameFilter class, see the documentation in Chapter 31, "Package java.io." |
getFilenameFilter | FileDialog |
public FilenameFilter getFilenameFilter()
The getFilenameFilter() method returns the current FilenameFilter being used by the FileDialog.
A FilenameFilter object containing the file filter displayed by the FileDialog. For more information on the FilenameFilter class, see the documentation in Chapter 31. |
FlowLayout |
Object |
LayoutManager |
The class hierarchy for the FlowLayout class derives from the class java.lang.Object. (See Listing 28.16.) A FlowLayout implements the LayoutManager interface. This class lays out buttons from left to right until no more buttons fit on the Panel. FlowLayout's overall derivation is shown in Figure 28.1.
Listing 28.16. Public members of java.awt.FlowLayout.
public class FlowLayout implements LayoutManager {
public static final int LEFT
public static final int CENTER
public static final int RIGHT
public FlowLayout()
public FlowLayout(int align)
public FlowLayout(int align, int hgap, int vgap)
public void addLayoutComponent(String name, Component comp)
public void removeLayoutComponent(Component comp)
public Dimension preferredLayoutSize(Container target)
public Dimension minimumLayoutSize(Container target)
public void layoutContainer(Container target)
public String toString()
}
Public Static Values |
public static final int LEFT
The LEFT static value represents the left alignment variable.
public static final int CENTER
The CENTER static value represents the center alignment variable.
public static final int RIGHT
The RIGHT static value represents the right alignment variable.
| FlowLayout | FlowLayout |
public FlowLayout()
This FlowLayout() constructor constructs a default FlowLayout class with a centered alignment.
None |
FlowLayout | FlowLayout |
public FlowLayout(int align)
This FlowLayout() constructor constructs a FlowLayout class using the specified alignment.
align is the alignment value (LEFT, CENTER, or RIGHT). |
FlowLayout | FlowLayout |
public FlowLayout(int align, int hgap, int vgap)
This FlowLayout() constructor constructs a FlowLayout class using the specified alignment and gap values.
align is the alignment value (LEFT, CENTER, or RIGHT). |
| hgap is the horizontal gap value. |
| vgap is the vertical gap value. |
addLayoutComponent | FlowLayout |
public void addLayoutComponent(String name, Component comp)
The addLayoutComponent() method adds a component to the FlowLayout class.
name is a String value representing the name of the component to be added. |
comp is the component object to be added to the FlowLayout. |
removeLayoutComponent | FlowLayout |
public void removeLayoutComponent(Component comp)
removeLayoutComponent() removes a component from the FlowLayout class.
comp is a component object to be removed from the FlowLayout. |
PreferredLayoutSize | FlowLayout |
public Dimension preferredLayoutSize(Container target)
The preferredLayoutSize() method returns the preferred size for this FlowLayout given the components in the specified container.
target is a Container object that is examined to determine the preferred layout size for this FlowLayout. |
| A Dimension class containing the preferred size of the FlowLayout. |
minimumLayoutSize | FlowLayout |
public Dimension minimumLayoutSize(Container target)
The minimumLayoutSize() method returns the minimum size for this FlowLayout given the components in the specified container.
target is a Container object that is examined to determine the minimum layout size for this FlowLayout. |
| A Dimension class containing the minimum size of the FlowLayout. |
layoutContainer | FlowLayout |
public void layoutContainer(Container target)
The layoutContainer() method lays out the components within the specified container.
target is a Container class containing a set of components that are laid out according to the FlowLayout rules. |
toString | FlowLayout |
public String toString()
The toString() method returns a string representation of the FlowLayout class.
A String containing information about the FlowLayout, including the FlowLayout's name, alignment, hgap, and vgap values. |
Font |
Object |
The class hierarchy for the Font class derives from the class java.lang.Object. (See Listing 28.17.) This class encapsulates a font. Font's overall derivation is shown in Figure 28.1.
Listing 28.17. Public members of java.awt.Font.
public class Font {
public static final int PLAIN
public static final int BOLD
public static final int ITALIC
public Font(String name, int style, int size)
public String getFamily()
public String getName()
public int getStyle()
public int getSize()
public boolean isPlain()
public boolean isBold()
public boolean isItalic()
public static Font getFont(String nm)
public static Font getFont(String nm, Font font)
public int hashCode()
public boolean equals(Object obj)
public String toString()
}
Public Static Values |
public static final int PLAIN
The PLAIN static value represents the plain style constant.
public static final int BOLD
The BOLD static value represents the bold style constant.
public static final int ITALIC
The ITALIC static value represents the italic style constant.
| Font | Font |
public Font(String name, int style, int size)
The Font() constructor constructs a Font of the specified name, style, and size.
name is the name of the font to be created. The possible fonts that can be created can be determined by calling the Toolkit class's getFontList() method. |
| style is the style (PLAIN, BOLD, and ITALIC) of the font to be created. |
| size is the size of the font to be created. |
getFamily | Font |
public String getFamily()
getFamily() returns the font family that this font belongs to.
A String value representing the Font's family name. |
getName | Font |
public String getName()
getName() returns the name of the Font object.
A String value representing the name of the Font. |
getStyle | Font |
public int getStyle()
getStyle() returns the style of the Font object.
An integer value representing the style of the Font. |
getSize | Font |
public int getSize()
getSize() returns the size of the Font object.
An integer value representing the point size of the Font. |
isPlain | Font |
public boolean isPlain()
isPlain() returns the plain style state of the Font.
A Boolean value that is true if the font is plain and false if it is not. |
isBold | Font |
public boolean isBold()
isBold() returns the bold style state of the Font.
A Boolean value that is true if the font is bold and false if it is not. |
isItalic | Font |
public boolean isItalic()
isItalic() returns the italic style state of the Font.
A Boolean value that is true if the font is italic and false if it is not. |
getFont | Font |
public static Font getFont(String nm)
getFont() returns a Font based on the system properties list and the name passed in.
nm is the name of the font to be returned from the system properties list. |
| A Font object based on the system properties list. |
getFont | Font |
public static Font getFont(String nm, Font font)
This getFont() method returns a Font based on the system properties list, the name passed in, and a default font in case the specified name is not found.
nm is the name of the font to be returned from the system properties list. |
| font is the default font to be returned if the font specified by the nm variable is not found. |
| A Font object based on the system properties list. |
hashCode | Font |
public int hashCode()
hashCode() returns a hash code for this font.
An integer value representing the hash code for the font. |
equals | Font |
public boolean equals(Object obj)
equals() compares an object with the Font object.
obj is the object to compare the Font with. |
| A Boolean value that is true if the objects are equal and false if they are not. |
toString | Font |
public String toString()
The toString() method returns a string representation of the Font.
A String value containing the Font family, name, style, and size values. |
FontMetrics |
Object |
The class hierarchy for the FontMetrics class derives from the class java.lang.Object. (See Listing 28.18.) The FontMetrics class encapsulates a font metrics object containing font information. FontMetrics' overall derivation is shown in Figure 28.1.
Listing 28.18. Public members of java.awt.FontMetrics.
public abstract class FontMetrics {
public Font getFont()
public int getLeading()
public int getAscent()
public int getDescent()
public int getHeight()
public int getMaxAscent()
public int getMaxDescent()
public int getMaxDecent()
public int getMaxAdvance()
public int charWidth(int ch)
public int charWidth(char ch)
public int stringWidth(String str)
public int charsWidth(char data[], int off, int len)
public int bytesWidth(byte data[], int off, int len)
public int[] getWidths()
public String toString()
}
getFont | FontMetrics |
public Font getFont()
The getFont() method returns the font that FontMetrics refers to.
A Font class. |
getLeading | FontMetrics |
public int getLeading()
The getLeading() method gets the line spacing of the font.
An integer value containing the standard leading, or line spacing, of the font. The line spacing of a font is the space reserved between the descent of a text character and the ascent of a text character below it. |
getAscent | FontMetrics |
public int getAscent()
The getAscent() method gets the ascent value for a Font.
An integer value containing the ascent value for a Font. This value is the distance from the bottom of a character to its top. |
getDescent | 3-2 | FontMetrics |
public int getDescent()
The getDescent() method gets the descent value for a Font.
An integer value containing the descent value for a Font. This value is the bottom coordinate of a character. |
getHeight | FontMetrics |
public int getHeight()
The getHeight() method gets the height of a line of text using the current Font.
An integer value containing the height of a line of text. This value is calculated by adding the ascent, descent, and leading values. |
getMaxAscent | FontMetrics |
public int getMaxAscent()
getMaxAscent() returns the maximum value of a font's ascent.
An integer value containing the maximum value of a font's ascent for all of that font's characters. |
getMaxDescent | FontMetrics |
public int getMaxDescent()
getMaxDescent() returns the maximum value of a font's descent.
An integer value containing the maximum value of a font's descent for all of that font's characters. |
getMaxDecent | FontMetrics |
public int getMaxDecent()
The getMaxDecent() method is provided only for backward compatibility. It simply calls the getMaxDescent() method.
An integer value containing the maximum value of a font's descent for all of that font's characters. |
getMaxAdvance | FontMetrics |
public int getMaxAdvance()
The getMaxAdvance() method gets the maximum amount for a character's advance value. The advance is the amount that is advanced from the beginning of one character to the next character.
| charWidth | FontMetrics |
public int charWidth(int ch)
charWidth() returns the width of a particular character for the current font.
ch is an integer value representing the character to be checked. |
| An integer value representing the width of the specified character. |
charWidth | FontMetrics |
public int charWidth(char ch)
This charWidth() method returns the width of a particular character for the current font.
ch is a char value representing the character to be checked. |
| An integer value representing the width of the specified character. |
stringWidth | FontMetrics |
public int stringWidth(String str)
The stringWidth() method returns the width of a specified string using the current font.
str is a string representing the characters to be checked. |
| An integer value representing the advance width of the specified string. |
charsWidth | FontMetrics |
public int charsWidth(char data[], int off, int len)
The charsWidth() method returns the width of a specified string of characters using the current font.
data is an array of characters to be checked. |
| off is an integer value representing the offset into the array where the string starts. |
| len is the number of characters to be measured. |
| An integer value representing the advance width of the specified string. |
bytesWidth | FontMetrics |
public int bytesWidth(byte data[], int off, int len)
The bytesWidth() method returns the width of a specified array of bytes.
data is an array of bytes to be checked. |
| off is an integer value representing the offset into the array where the string starts. |
| len is the number of bytes to be measured. |
| An integer value representing the advance width of the specified string. |
getWidths | FontMetrics |
public int[] getWidths()
The getWidths() method gets the advance widths of the first 256 characters of the font.
An integer array containing the advance widths of the first 256 characters of the font. |
toString | FontMetrics |
public String toString()
The toString() method returns a string representation of the FontMetrics class.
A String value containing the FontMetrics' name, font, ascent, descent, and height. |
Frame |
Window |
MenuContainer |
The class hierarchy for the Frame class derives from the class java.awt.Window. (See Listing 28.19.) A Frame class represents a basic window. Frame's overall derivation is shown in Figure 28.1.
Listing 28.19. Public members of java.awt.Frame.
public class Frame extends Window implements MenuContainer {
public static final int DEFAULT_CURSOR
public static final int CROSSHAIR_CURSOR
public static final int TEXT_CURSOR
public static final int WAIT_CURSOR
public static final int SW_RESIZE_CURSOR
public static final int SE_RESIZE_CURSOR
public static final int NW_RESIZE_CURSOR
public static final int NE_RESIZE_CURSOR
public static final int N_RESIZE_CURSOR
public static final int S_RESIZE_CURSOR
public static final int W_RESIZE_CURSOR
public static final int E_RESIZE_CURSOR
public static final int HAND_CURSOR
public static final int MOVE_CURSOR
public Frame()
public Frame(String title)
public synchronized void addNotify()
public String getTitle()
public void setTitle(String title)
public Image getIconImage()
public void setIconImage(Image image)
public MenuBar getMenuBar()
public synchronized void setMenuBar(MenuBar mb)
public synchronized void remove(MenuComponent m)
public synchronized void dispose()
public boolean isResizable()
public void setResizable(boolean resizable)
public void setCursor(int cursorType)
public int getCursorType()
}
Public Static Values |
public static final int DEFAULT_CURSOR
The DEFAULT_CURSOR static value represents the default cursor.
public static final int CROSSHAIR_CURSOR
The CROSSHAIR_CURSOR static value represents the crosshair cursor.
public static final int TEXT_CURSOR
The TEXT_CURSOR static value represents the text cursor.
public static final int WAIT_CURSOR
The WAIT_CURSOR static value represents the wait cursor.
public static final int SW_RESIZE_CURSOR
The SW_RESIZE_CURSOR static value represents the southwest resize cursor.
public static final int SE_RESIZE_CURSOR
The SE_RESIZE_CURSOR static value represents the southeast resize cursor.
public static final int NW_RESIZE_CURSOR
The NW_RESIZE_CURSOR static value represents the northwest resize cursor.
public static final int NE_RESIZE_CURSOR
The NE_RESIZE_CURSOR static value represents the northeast resize cursor.
public static final int N_RESIZE_CURSOR
The N_RESIZE_CURSOR static value represents the north resize cursor.
public static final int S_RESIZE_CURSOR
The S_RESIZE_CURSOR static value represents the south resize cursor.
public static final int W_RESIZE_CURSOR
The W_RESIZE_CURSOR static value represents the west resize cursor.
public static final int E_RESIZE_CURSOR
The E_RESIZE_CURSOR static value represents the east resize cursor.
public static final int HAND_CURSOR
The HAND_CURSOR static value represents the hand cursor.
public static final int MOVE_CURSOR
The MOVE_CURSOR static value represents the move cursor.
| Frame | Frame |
public Frame()
The Frame() constructor constructs a default frame that is invisible and that uses the BorderLayout layout manager.
| Frame | Frame |
public Frame(String title)
This Frame() constructor constructs a default frame using the specified title that is invisible and that uses the BorderLayout layout manager.
title is a String value containing the Frame's title string. |
addNotify | Frame |
public synchronized void addNotify()
The addNotify() method creates a peer interface for the Frame. Peer interfaces allow you to change the user interface of the frame without changing its functionality.
none |
getTitle | Frame |
public String getTitle()
getTitle() returns the frame's title.
A String value representing the title of the Frame. |
setTitle | Frame |
public void setTitle(String title)
setTitle() sets the frame's title.
title is a String value representing the title of the Frame. |
getIconImage | Frame |
public Image getIconImage()
The getIconImage() method returns an Image representing the iconized image of the Frame.
An Image class representing the iconized image of the frame. |
setIconImage | Frame |
public void setIconImage(Image image)
setIconImage() sets the image that is used when the frame is iconized.
image is an Image class that is displayed when the frame is iconized. |
getMenuBar | Frame |
public MenuBar getMenuBar()
The getMenuBar() method returns the MenuBar object that is contained within this frame.
A MenuBar class that is displayed within this frame. |
setMenuBar | Frame |
public synchronized void setMenuBar(MenuBar mb)
setMenuBar() sets the MenuBar class to be displayed within the Frame.
mb is a MenuBar class to be used for the frame's menu bar. |
remove | Frame |
public synchronized void remove(MenuComponent m)
The remove() method removes the specified MenuComponent from the frame.
m is a MenuComponent object that is to be removed from the frame. |
dispose | Frame |
public synchronized void dispose()
The dispose() method disposes of the Frame. This method first disposes of the frame's menu bar and then disposes of the frame itself.
| isResizable | Frame |
public boolean isResizable()
The isResizable() method returns the frame's resizable state.
A Boolean value that is true if the frame can be resized and false if it can't. |
setResizable | Frame |
public void setResizable(boolean resizable)
The setResizable() method sets the frame's resizable state.
A Boolean value that is true if the frame can be resized and false if it can't. |
setCursor | Frame |
public void setCursor(int cursorType)
The setCursor() method sets the cursor to be displayed within the frame.
cursorType is an integer value representing the cursor to be displayed. This can be any of the frame's static values such as WAIT_CURSOR, MOVE_CURSOR, and so on. |
getCursorType | Frame |
public int getCursorType()
The getCursorType() method returns the frame's current cursor type.
An integer value representing the current cursor type for the frame. |
Graphics |
Object |
The class hierarchy for the Graphics class derives from the class java.lang.Object. (See Listing 28.20.) The Graphics class represents the base class for all types of graphics contexts. Graphics's overall derivation is shown in Figure 28.1.
Listing 28.20. Public members of java.awt.Graphics.
public abstract class Graphics {
public abstract Graphics create()
public Graphics create(int x, int y, int width, int height)
public abstract void translate(int x, int y)
public abstract Color getColor()
public abstract void setColor(Color c)
public abstract void setPaintMode()
public abstract void setXORMode(Color c1)
public abstract Font getFont()
public abstract void setFont(Font font)
public FontMetrics getFontMetrics()
public abstract FontMetrics getFontMetrics(Font f)
public abstract Rectangle getClipRect()
public abstract void clipRect(int x, int y, int width, int height)
public abstract void copyArea(int x, int y, int width, int height, int dx,
int dy)
public abstract void drawLine(int x1, int y1, int x2, int y2)
public abstract void fillRect(int x, int y, int width, int height)
public void drawRect(int x, int y, int width, int height)
public abstract void clearRect(int x, int y, int width, int height)
public abstract void drawRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight)
public abstract void fillRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight)
public void draw3DRect(int x, int y, int width, int height, boolean raised)
public void fill3DRect(int x, int y, int width, int height, boolean raised)
public abstract void drawOval(int x, int y, int width, int height)
public abstract void fillOval(int x, int y, int width, int height)
public abstract void drawArc(int x, int y, int width, int height,
int startAngle, int arcAngle)
public abstract void fillArc(int x, int y, int width, int height,
int startAngle, int arcAngle)
public abstract void drawPolygon(int xPoints[], int yPoints[], int nPoints)
public void drawPolygon(Polygon p)
public abstract void fillPolygon(int xPoints[], int yPoints[], int nPoints)
public void fillPolygon(Polygon p)
public abstract void drawString(String str, int x, int y)
public void drawChars(char data[], int offset, int length, int x, int y)
public void drawBytes(byte data[], int offset, int length, int x, int y)
public abstract boolean drawImage(Image img, int x, int y,
ImageObserver observer)
public abstract boolean drawImage(Image img, int x, int y,
int width, int height,
ImageObserver observer)
public abstract boolean drawImage(Image img, int x, int y,
Color bgcolor,
ImageObserver observer)
public abstract boolean drawImage(Image img, int x, int y,
int width, int height,
Color bgcolor,
ImageObserver observer)
public abstract void dispose()
public void finalize()
public String toString()
}
create | Graphics |
public abstract Graphics create()
This abstract function creates a new graphics object.
| Create | Graphics |
public Graphics create(int x, int y, int width, int height)
The create() method creates a new Graphics object using the specified parameters.
X is the x coordinate of the graphics context. |
| Y is the y coordinate of the graphics context. |
| Width is the width of the graphics context. |
| height is the height of the graphics context. |
| A Graphics class corresponding to the create() method's specifications. |
translate | Graphics |
public abstract void translate(int x, int y)
The translate() method translates the Graphics object to the new x and y origin coordinates.
x is the new x origin coordinate. |
| y is the new y origin coordinate. |
getColor | Graphics |
public abstract Color getColor()
The getColor() method returns the current color.
A Color object representing the current color used for drawing operations. For more information on the Color class, see the documentation earlier in this chapter. |
setColor | Graphics |
public abstract void setColor(Color c)
The setColor() method sets the current color.
c is a Color object to be used for graphics drawing operations. For more information on the Color class, see the documentation earlier in this chapter. |
setPaintMode | Graphics |
public abstract void setPaintMode()
The setPaintMode() method sets the paint mode to overwrite the destination with the current color.
| setXORMode | Graphics |
public abstract void setXORMode(Color c1)
The setXORMode() method sets the paint mode to XOR the current colors with the specified color. This means that when redrawing over an existing area, colors that match the current color are changed to the specified color c1 and vice versa.
c1 is the Color object specified to be XORed with the current color. For more information on the Color class, see the documentation earlier in this chapter. |
getFont | Graphics |
public abstract Font getFont()
The getFont() method returns the current font used for the graphics context.
A Font object representing the graphics context's current Font. For more information on the Font class, see the documentation earlier in this chapter. |
setFont | Graphics |
public abstract void setFont(Font font)
The setFont() method sets the graphics context's font.
font is a Font object that is used as the current font. For more information on the Font class, see the documentation earlier in this chapter. |
getFontMetrics | Graphics |
public FontMetrics getFontMetrics()
The getFontMetrics() method returns the font metrics for the current font.
A FontMetrics object representing the font metrics for the current font. For more information on the FontMetrics class, see the documentation earlier in this chapter. |
getFontMetrics | Graphics |
public abstract FontMetrics getFontMetrics(Font f)
This getFontMetrics() method returns the font metrics for the specified font.
A FontMetrics object representing the font metrics for the specified font. For more information on the FontMetrics class, see the documentation earlier in this chapter. |
getClipRect | Graphics |
public abstract Rectangle getClipRect()
The getClipRect() method returns the current clipping rectangle for the Graphics class.
A Rectangle object representing the current clipping rectangle. For more information on the Rectangle class, see the documentation later in this chapter. |
clipRect | Graphics |
public abstract void clipRect(int x, int y, int width, int height)
The clipRect() method sets the current clipping rectangle for the Graphics class.
x is the x coordinate of the clipping rectangle. |
| y is the y coordinate of the clipping rectangle. |
| width is the width of the clipping rectangle. |
| height is the height of the clipping rectangle. |
copyArea | Graphics |
public abstract void copyArea(int x, int y, int width, int height, int dx, int dy)
The copyArea() method copies a specified section of the screen to another location.
x is the x coordinate of the region to be copied. |
| y is the y coordinate of the region to be copied. |
| width is the width of the region to be copied. |
| height is the height of the region to be copied. |
| dx is the horizontal distance of the region to be copied to. |
| dy is the vertical distance of the region to be copied to. |
drawLine | Graphics |
public abstract void drawLine(int x1, int y1, int x2, int y2)
The drawLine() method draws a line on the graphics context from one point to another point specified by the input parameters.
x1 is the x coordinate of the line's starting point. |
| y1 is the y coordinate of the line's starting point. |
| x2 is the x coordinate of the line's ending point. |
| y2 is the y coordinate of the line's ending point. |
fillRect | Graphics |
public abstract void fillRect(int x, int y, int width, int height)
The fillRect() method fills the specified rectangular region with the current Color.
x is the x coordinate of the rectangle to be filled. |
| y is the y coordinate of the rectangle to be filled. |
| width is the width of the rectangle to be filled. |
| height is the height of the rectangle to be filled. |
drawRect | Graphics |
public void drawRect(int x, int y, int width, int height)
The drawRect() method draws the outline of a rectangle using the current color and the specified dimensions.
x is the x coordinate of the rectangle to be drawn. |
| y is the y coordinate of the rectangle to be drawn. |
| width is the width of the rectangle to be drawn. |
| height is the height of the rectangle to be drawn. |
clearRect | Graphics |
public abstract void clearRect(int x, int y, int width, int height)
The clearRect() method clears a rectangle by filling it with the current background color of the current drawing surface.
x is the x coordinate of the rectangle to be cleared. |
| y is the y coordinate of the rectangle to be cleared. |
| width is the width of the rectangle to be cleared. |
| height is the height of the rectangle to be cleared. |
drawRoundRect | Graphics |
public abstract void drawRoundRect(int x, int y, int width, int height,
 int arcWidth, int arcHeight)
The drawRoundRect() method draws the outline of a rectangle with rounded edges using the current color and the specified coordinates.
x is the x coordinate of the rectangle to be drawn. |
| y is the y coordinate of the rectangle to be drawn |
| width is the width of the rectangle to be drawn. |
| height is the height of the rectangle to be drawn. |
| arcWidth is the horizontal diameter of the arc at the four corners. |
| arcHeight is the vertical diameter of the arc at the four corners. |
fillRoundRect | Graphics |
public abstract void fillRoundRect(int x, int y, int width, int height,
 int arcWidth, int arcHeight)
The fillRoundRect() method fills a rectangle with rounded edges using the current color and the specified coordinates.
x is the x coordinate of the rectangle to be filled. |
| y is the y coordinate of the rectangle to be filled. |
| width is the width of the rectangle to be filled. |
| height is the height of the rectangle to be filled. |
| arcWidth is the horizontal diameter of the arc at the four corners. |
| arcHeight is the vertical diameter of the arc at the four corners. |
draw3DRect | Graphics |
public void draw3DRect(int x, int y, int width, int height, boolean raised)
The draw3DRect() method draws a highlighted 3D rectangle at a default viewing angle.
x is the x coordinate of the rectangle to be drawn. |
| y is the y coordinate of the rectangle to be drawn. |
| width is the width of the rectangle to be drawn. |
| height is the height of the rectangle to be drawn. |
| raised is a Boolean value determining whether the rectangle is raised or not. |
fill3DRect | Graphics |
public void fill3DRect(int x, int y, int width, int height, boolean raised)
The fill3DRect() method fills a highlighted 3D rectangle using the current color and specified coordinates at a default viewing angle.
x is the x coordinate of the rectangle to be filled. |
| y is the y coordinate of the rectangle to be filled. |
| width is the width of the rectangle to be filled. |
| height is the height of the rectangle to be filled. |
| raised is a Boolean value determining whether the rectangle is raised or not. |
drawOval | Graphics |
public abstract void drawOval(int x, int y, int width, int height)
The drawOval() method draws the outline of an oval shape using the current color and the specified coordinates. The oval is drawn inside the rectangle represented by the input coordinates.
x is the x coordinate of the rectangle to draw the oval within. |
| y is the y coordinate of the rectangle to draw the oval within. |
| width is the width of the rectangle to draw the oval within. |
| height is the height of the rectangle to draw the oval within. |
fillOval | Graphics |
public abstract void fillOval(int x, int y, int width, int height)
The fillOval() method fills an oval using the current color and the specified coordinates. The oval is drawn inside the rectangle represented by the input coordinates.
x is the x coordinate of the rectangle to draw the oval within. |
| y is the y coordinate of the rectangle to draw the oval within. |
| width is the width of the rectangle to draw the oval within. |
| height is the height of the rectangle to draw the oval within. |
drawArc | Graphics |
public abstract void drawArc(int x, int y, int width, int height,
 int startAngle, int arcAngle)
The drawArc() method draws an arc outline using the current color that is bounded by the specified input coordinates. Note that 0 degrees represents the 3 o'clock position and that positive angles are measured in a counterclockwise direction.
x is the x coordinate of the rectangle to draw the arc within. |
| y is the y coordinate of the rectangle to draw the arc within. |
| width is the width of the rectangle to draw the arc within. |
| height is the height of the rectangle to draw the arc within. |
| startAngle is the starting angle of the arc to be drawn. |
| arcAngle is the angle of the arc relative to the start angle. |
fillArc | Graphics |
public abstract void fillArc(int x, int y, int width, int height,
 int startAngle, int arcAngle)
The fillArc() method fills an arc using the current color that is bounded by the specified input coordinates. Note that 0 degrees represents the 3 o'clock position and that positive angles are measured in a counterclockwise direction.
x is the x coordinate of the rectangle to draw the arc within. |
| y is the y coordinate of the rectangle to draw the arc within. |
| width is the width of the rectangle to draw the arc within. |
| height is the height of the rectangle to draw the arc within. |
| startAngle is the starting angle of the arc to be drawn. |
| arcAngle is the angle of the arc relative to the start angle. |
drawPolygon | Graphics |
public abstract void drawPolygon(int xPoints[], int yPoints[], int nPoints)
The drawPolygon() method draws a polygon using the current color and the specified coordinates.
xPoints is an array of integers containing the starting x coordinates for each edge of the polygon. |
| yPoints is an array of integers containing the starting y coordinates for each edge of the polygon. |
| nPoints is an integer value representing the number of edges of the polygon. |
drawPolygon | Graphics |
public void drawPolygon(Polygon p)
This drawPolygon() method draws a polygon using the specified Polygon class.
p is a Polygon class containing the coordinates for the polygon to be drawn. For more information on the Polygon class, see the documentation later in this chapter. |
fillPolygon | Graphics |
public abstract void fillPolygon(int xPoints[], int yPoints[], int nPoints)
The fillPolygon() method fills a polygon using the current color and the specified coordinates.
xPoints is an array of integers containing the starting x coordinates for each edge of the polygon. |
| yPoints is an array of integers containing the starting y coordinates for each edge of the polygon. |
| nPoints is an integer value representing the number of edges of the polygon. |
fillPolygon | Graphics |
public void fillPolygon(Polygon p)
This fillPolygon() method fills a polygon using the specified Polygon class and the current color.
p is a Polygon class containing the coordinates for the polygon to be drawn. For more information on the Polygon class, see the documentation later in this chapter. |
drawString | Graphics |
public abstract void drawString(String str, int x, int y)
The drawString() method draws a string using the current font at the specified coordinates.
str is the string to be displayed. |
| x is the x coordinate of where the string is drawn. |
| y is the y coordinate of where the string is drawn. |
drawChars | Graphics |
public void drawChars(char data[], int offset, int length, int x, int y)
The drawChars() method draws a string using the current font at the specified coordinates.
data is an array of characters. |
| offset is the offset within the array of characters where the displayed string starts. |
| length is the number of characters to draw. |
| x is the x coordinate of where the string is drawn. |
| y is the y coordinate of where the string is drawn. |
drawBytes | Graphics |
public void drawBytes(byte data[], int offset, int length, int x, int y)
The drawChars() method draws a string using the current font at the specified coordinates.
data is an array of bytes. |
| offset is the offset within the array of bytes where the displayed string starts. |
| length is the number of bytes to draw. |
| x is the x coordinate of where the string is drawn. |
| y is the y coordinate of where the string is drawn. |
drawImage | Graphics |
public abstract boolean drawImage(Image img, int x, int y,
 ImageObserver observer)
The drawImage() method draws an image at a specified location.
img is an Image class to be drawn using the graphics context. |
| x is the x coordinate of where the image is drawn. |
| y is the y coordinate of where the image is drawn. |
| observer is an ImageObserver interface that notifies when the drawing is done. |
| A Boolean value indicating the success or failure of the draw operation. |
drawImage | Graphics |
public abstract boolean drawImage(Image img, int x, int y, int width,
 int height, ImageObserver observer)
This drawImage() method draws an image at a specified location within the specified bounding rectangle.
img is an Image class to be drawn using the graphics context. |
| x is the x coordinate of where the image is drawn. |
| y is the y coordinate of where the image is drawn. |
| width is the width of the rectangle to draw the image within. |
| height is the height of the rectangle to draw the image within. |
| observer is an ImageObserver interface that notifies when the drawing is done. |
| A Boolean value indicating the success or failure of the draw operation. |
drawImage | Graphics |
public abstract boolean drawImage(Image img, int x, int y, Color bgcolor,
 ImageObserver observer)
This drawImage() method draws an image at a specified location using the specified background color.
img is an Image class to be drawn using the graphics context. |
| x is the x coordinate of where the image is drawn. |
| y is the y coordinate of where the image is drawn. |
| bgcolor is the background color to be used. |
| observer is an ImageObserver interface that notifies when the drawing is done. |
| A Boolean value indicating the success or failure of the draw operation. |
drawImage | Graphics |
public abstract boolean drawImage(Image img, int x, int y, int width,
 int height, Color bgcolor, ImageObserver observer)
The drawImage() method draws an image at a specified location within a specified bounding rectangle using a specified background color.
img is an Image class to be drawn using the graphics context. |
| x is the x coordinate of where the image is drawn. |
| y is the y coordinate of where the image is drawn. |
| width is the width of the bounding rectangle. |
| height is the height of the bounding rectangle. |
| bgcolor is the background color to be used. |
| observer is an ImageObserver interface that notifies when the drawing is done. |
| A Boolean value indicating the success or failure of the draw operation. |
dispose | Graphics |
public abstract void dispose()
The dispose() method disposes of the Graphics object.
none |
finalize | Graphics |
public void finalize()
The finalize() method disposes of the Graphics object once it is no longer referenced.
none |
toString | Graphics |
public String toString()
The toString() method returns a string representation of the Graphics object.
A String containing the Graphics class name, current color, and current font. |
GridBagConstraints |
Object |
Cloneable |
The class hierarchy for the GridBagConstraints class derives from the class java.lang.Object. (See Listing 28.21.) A GridBagConstraints class is used in conjunction with a GridBagLayout in order to specify the constraints of the objects being laid out. GridBagConstraints' overall derivation is shown in Figure 28.1.
Listing 28.21. Public members of java.awt.GridBagConstraints.
public class GridBagConstraints implements Cloneable {
public static final int RELATIVE
public static final int REMAINDER
public static final int NONE
public static final int BOTH
public static final int HORIZONTAL
public static final int VERTICAL
public static final int CENTER
public static final int NORTH
public static final int NORTHEAST
public static final int EAST
public static final int SOUTHEAST
public static final int SOUTH
public static final int SOUTHWEST
public static final int WEST
public static final int NORTHWEST
public int gridx, gridy, gridwidth, gridheight
public double weightx, weighty
public int anchor, fill
public Insets insets
public int ipadx, ipady
public GridBagConstraints()
public Object clone()
}
Public Static Values |
public static final int RELATIVE
A public static value representing the relative constraint.
public static final int REMAINDER
A public static value representing the remainder constraint.
public static final int NONE
A public static value representing the none constraint.
public static final int BOTH
A public static value representing the both constraint.
public static final int HORIZONTAL
A public static value representing the horizontal constraint.
public static final int VERTICAL
A public static value representing the vertical constraint.
public static final int CENTER
A public static value representing the center constraint.
public static final int NORTH
A public static value representing the north constraint.
public static final int NORTHEAST
A public static value representing the northeast constraint.
public static final int EAST
A public static value representing the east constraint.
public static final int SOUTHEAST
A public static value representing the southeast constraint.
public static final int SOUTH
A public static value representing the south constraint.
public static final int SOUTHWEST
A public static value representing the southwest constraint.
public static final int WEST
A public static value representing the west constraint.
public static final int NORTHWEST
A public static value representing the northwest constraint.
Public Instance Variables |
public int gridx
The gridx variable stores the grid x coordinate.
public int gridy
The gridy variable stores the grid y coordinate.
public int gridwidth
The gridwidth variable stores the grid bounding rectangle width.
public int gridheight
The gridheight variable stores the grid bounding rectangle height.
public double weightx
The weightx variable stores the horizontal space for a component to reserve for itself. If this is set to zero (the default), all components within a row are bunched together in the center of the row.
public double weighty
The weighty variable stores the vertical space for a component to reserve for itself. If this is set to zero (the default), all components within a column are bunched together in the center of the column.
public int anchor
The anchor variable determines how to display a component when it is smaller than its display area. Valid values for this variable are CENTER (the default), NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, and NORTHWEST.
public int fill
The fill variable determines how to display a component when it is larger than its display area. Valid values for this variable are NONE, HORIZONTAL, VERTICAL, and BOTH.
public Insets insets
The insets variable determines the space between the component and its bounding area. For more information on the Insets class, see the documentation later in this chapter.
public int ipadx
The ipadx variable determines the amount of padding to always add to the component on its left and right sides.
public int ipady
The ipady variable determines the amount of padding to always add to the component on its top and bottom sides.
| GridBagConstraints | GridBagConstraints |
public GridBagConstraints()
The GridBagConstraints() constructor creates a GridBagConstraints class containing default values. The default values are
gridx = RELATIVE;
gridy = RELATIVE
gridwidth = 1
gridheight = 1
weightx = 0
weighty = 0
anchor = CENTER
fill = NONE
insets = new Insets(0, 0, 0, 0)
ipadx = 0
ipady = 0
clone | GridBagConstraints |
public Object clone()
The clone() method creates a clone of this GridBagConstraints object.
An Object object representing a clone of this GridBagConstraints object. |
GridBagLayout |
Object |
| LayoutManager |
The class hierarchy for the GridBagLayout class derives from the class java.lang.Object. (See Listing 28.22.) The GridBagLayout implements the LayoutManager interface. This class uses a rectangular grid of cells to lay out components within the cells. Each component is associated with a GridBagConstraints object that controls how the component is actually laid out within the grid. GridBagLayout's overall derivation is shown in Figure 28.1.
Listing 28.22. Public members of java.awt.GridBagLayout.
public class GridBagLayout implements LayoutManager {
public int columnWidths[]
public int rowHeights[]
public double columnWeights[]
public double rowWeights[]
public GridBagLayout()
public void setConstraints(Component comp, GridBagConstraints constraints)
public GridBagConstraints getConstraints(Component comp)
public Point getLayoutOrigin()
public int [][] getLayoutDimensions()
public double [][] getLayoutWeights()
public Point location(int x, int y)
public void addLayoutComponent(String name, Component comp)
public void removeLayoutComponent(Component comp)
public Dimension preferredLayoutSize(Container parent)
public Dimension minimumLayoutSize(Container parent)
public void layoutContainer(Container parent)
public String toString()
}
Public Instance Variables |
public int columnWidths[]
The columnWidths variable is an array of integers representing the widths of each column used by the GridBagLayout.
public int rowHeights[]
The rowHeights variable is an array of integers representing the heights of each row used by the GridBagLayout.
public double columnWeights[]
The columnWeights variable is an array of doubles representing the space to be distributed for each column.
public double rowWeights[]
The rowWeights variable is an array of doubles representing the space to be distributed for each row.
| GridBagLayout | GridBagLayout |
public GridBagLayout()
The GridBagLayout() constructor constructs a GridBagLayout class for use in laying out components on a form.
| setConstraints | GridBagLayout |
public void setConstraints(Component comp, GridBagConstraints constraints)
The setConstraints() method sets the GridBagConstraints for the specified component.
comp is a Component to be modified within the GridBagLayout. |
| constraints is the GridBagConstraints that is applied to the component. |
getConstraints | GridBagLayout |
public GridBagConstraints getConstraints(Component comp)
The getConstraints() method returns the constraints currently applied to the specified component.
Comp is a Component managed by the GridBagLayout. |
| A GridBagConstraints class representing the constraints placed upon the specified component. |
GetLayoutOrigin | GridBagLayout |
public Point getLayoutOrigin()
The getLayoutOrigin() method returns the origin of the layout manager.
A Point class representing the origin of the GridBagLayout. For more information on the Point class, see the documentation later in this chapter. |
GetLayoutDimensions | GridBagLayout |
public int [][] getLayoutDimensions()
The getLayoutDimensions() method returns an array of dimensions with an element for each component.
An array containing layout dimensions for components managed by the GridBagLayout. |
getLayoutWeights | GridBagLayout |
public double [][] getLayoutWeights()
The getLayoutWeights() method returns an array of weights with an element for each component.
An array containing layout weights for components managed by the GridBagLayout. |
location | GridBagLayout |
public Point location(int x, int y)
The location() method returns a Point object representing the point within the layout manager corresponding to the specified coordinates.
x is the x coordinate. |
| y is the y coordinate. |
| A Point object. For more information on the Point class, see the documentation later in this chapter. |
addLayoutComponent | GridBagLayout |
public void addLayoutComponent(String name, Component comp)
The addLayoutComponent() method adds a component to the GridBagLayout.
name is the name of the component to be added. |
| comp is the Component to be added. |
removeLayoutComponent | GridBagLayout |
public void removeLayoutComponent(Component comp)
The removeLayoutComponent() method removes a component from the GridBagLayout.
comp is the Component to be removed. |
preferredLayoutSize | GridBagLayout |
public Dimension preferredLayoutSize(Container parent)
The preferredLayoutSize() method returns the preferred size for the layout manager given the specified container and the components within it.
parent is a Container object containing components. For more information on the Container class, see the documentation earlier in this chapter. |
| A Dimension object specifying the preferred size of the layout manager. For more information on the Dimension class, see the documentation earlier in this chapter. |
minimumLayoutSize | GridBagLayout |
public Dimension minimumLayoutSize(Container parent)
The minimumLayoutSize() method returns the minimum size for the layout manager given the specified container and the components within it.
parent is a Container object containing components. For more information on the Container class, see the documentation earlier in this chapter. |
| A Dimension object specifying the minimum size of the layout manager. For more information on the Dimension class, see the documentation earlier in this chapter. |
layoutContainer | GridBagLayout |
public void layoutContainer(Container parent)
The layoutContainer() method lays out the specified container within the layout manager.
parent is a Container object containing components. For more information on the Container class, see the documentation earlier in this chapter. |
toString | GridBagLayout |
public String toString()
The toString() method returns a string containing information about the GridBagLayout.
A String containing the name of the GridBagLayout. |
GridLayout |
Object |
LayoutManager |
The class hierarchy for the GridLayout class derives from the class java.lang.Object. (See Listing 28.23.) The GridLayout class implements the LayoutManager interface. It lays out grid objects. GridLayout's overall derivation is shown in Figure 28.1.
Listing 28.23. Public members of java.awt.GridLayout.
public class GridLayout implements LayoutManager {
public GridLayout(int rows, int cols)
public GridLayout(int rows, int cols, int hgap, int vgap)
public void addLayoutComponent(String name, Component comp)
public void removeLayoutComponent(Component comp)
public Dimension preferredLayoutSize(Container parent)
public Dimension minimumLayoutSize(Container parent)
public void layoutContainer(Container parent)
public String toString()
}
GridLayout | GridLayout |
public GridLayout(int rows, int cols)
The GridLayout() constructor constructs a grid layout manager using the specified number of rows and columns.
rows is the number of rows to be laid out. Either rows or cols can be set to zero in order to set either the rows or columns to 'any number.' |
| cols is the number of columns to be laid out. Either rows or cols can be set to zero in order to set either the rows or columns to 'any number.' |
GridLayout | GridLayout |
public GridLayout(int rows, int cols, int hgap, int vgap)
This GridLayout() constructor constructs a grid layout manager using the specified number of rows and columns as well as the horizontal and vertical gaps to be used.
rows is the number of rows to be laid out. |
| cols is the number of columns to be laid out. |
| hgap is the horizontal gap value. |
| vgap is the vertical gap value. |
addLayoutComponent | GridLayout |
public void addLayoutComponent(String name, Component comp)
The addLayoutComponent() method adds a component to the GridLayout.
name is the name of the component to be added. |
| comp is the component to be added. |
removeLayoutComponent | GridLayout |
public void removeLayoutComponent(Component comp)
The removeLayoutComponent() method removes a component from the GridBagLayout.
comp is the component to be removed. |
preferredLayoutSize | GridLayout |
public Dimension preferredLayoutSize(Container parent)
The preferredLayoutSize() method returns the preferred size for the layout manager given the specified container and the components within it.
parent is a Container object containing components. For more information on the Container class, see the documentation earlier in this chapter. |
| A Dimension object specifying the preferred size of the layout manager. For more information on the Dimension class, see the documentation earlier in this chapter. |
minimumLayoutSize | GridLayout |
public Dimension minimumLayoutSize(Container parent)
The minimumLayoutSize() method returns the minimum size for the layout manager given the specified container and the components within it.
parent is a Container object containing components. For more information on the Container class, see the documentation earlier in this chapter. |
| A Dimension object specifying the minimum size of the layout manager. For more information on the Dimension class, see the documentation earlier in this chapter. |
layoutContainer | GridLayout |
public void layoutContainer(Container parent)
The layoutContainer() method lays out the specified container within the layout manager.
parent is a Container object containing components. For more information on the Container class, see the documentation earlier in this chapter. |
toString | GridLayout |
public String toString()
The toString() method returns a string containing information about the GridLayout.
A String containing the GridLayout's name, hgap, vgap, rows, and cols values. |
Image |
Object |
The class hierarchy for the Image class derives from the class java.lang.Object. (See Listing 28.24.) An Image class is actually an abstract class. You must provide a platform-specific implementation to use it. Image's overall derivation is shown in Figure 28.1.
Listing 28.24. Public members of java.awt.Image.
public abstract class Image {
public abstract int getWidth(ImageObserver observer)
public abstract int getHeight(ImageObserver observer)
public abstract ImageProducer getSource()
public abstract Graphics getGraphics()
public abstract Object getProperty(String name, ImageObserver observer)
public static final Object UndefinedProperty
public abstract void flush()
}
getWidth | Image |
public abstract int getWidth(ImageObserver observer)
The getWidth() method returns the width of the Image. If the width of the image is not yet known, the ImageObserver is notified at a later time and -1 is returned.
Observer is an ImageObserver interface that is notified if the image is not yet available. |
| An integer value representing the width of the image (-1 if the image is not yet available). |
GetHeight | Image |
public abstract int getHeight(ImageObserver observer)
The getWidth() method returns the height of the Image. If the height of the image is not yet known, the ImageObserver is notified at a later time and -1 is returned.
Observer is an ImageObserver interface that is notified if the image is not yet available. |
| An integer value representing the height of the image (-1 if the image is not yet available). |
GetSource | Image |
public abstract ImageProducer getSource()
The getSource() method returns the ImageProducer interface responsible for producing the Image's pixels.
An ImageProducer interface used by the image filtering classes in package java.awt.Image (see documentation later in this chapter). |