The java.awt package contains what is known as the Java Abstract Windowing Toolkit. The classes within this package make up the prebuilt 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.
The LayoutManager interface is provided so that it can be implemented by objects that know how to lay out containers.
void addLayoutComponent(String name, Component comp)
The addLayoutComponent method lays out the specified component within the layout manager.
Parameters:
name-the name of the component to be laid out.
comp-the Component object to be laid out within the layout manager.
void removeLayoutComponent(Component comp)
The removeLayoutComponent method removes a specified component from the layout manager.
Parameters: comp-the Component object that is to be removed from within the layout manager.
Dimension preferredLayoutSize(Container parent)
The preferredLayoutSize method determines the preferred layout size for a specified container.
Parameters: parent-a Container object that is to be laid out using the layout manager.
Returns: A Dimension object containing the preferred size of the Container parameter.
Dimension minimumLayoutSize(Container parent)
The minimumLayoutSize method determines the minimum layout size for a specified container.
Parameters: parent-a Container object that is to be laid out using the layout manager.
Returns: A Dimension object containing the minimum size of the Container parameter.
void layoutContainer(Container parent)
The layoutContainer method will lay out the specified Container object within the layout manager.
Parameters: parent-a Container object that is to be laid out using the layout manager.
The MenuContainer is an interface that is implemented by all menu-related containers.
Font getFont()
The getFont method returns the current font of the menu container.
Returns: The current Font object.
boolean postEvent(Event evt)
The postEvent method posts the specified event to the MenuContainer.
Parameters: evt-the Event object to be posted to the menu container.
Returns: A boolean value containing true if the event was handled, false if not.
void remove(MenuComponent comp)
The remove method removes the specified MenuComponent object from the MenuContainer.
Parameters: comp-the MenuComponent class to be removed from the MenuContainer.
Extends: Object
Implements: LayoutManager
A BorderLayout is used to lay out components on a panel by implementing the LayoutManager interface. Components are laid out using members named North, South, East, West, and Center.
public BorderLayout()
This BorderLayout constructor constructs a BorderLayout layout manager.
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.
Parameters:
hgap-an integer value used to set the horizontal gap size.
vgap-an integer value used to set the vertical gap size.
public void addLayoutComponent(String name, Component comp)
addLayoutComponent adds a component to the border layout 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.
Parameters:
name-a string value that must correspond to one of the following names: North, South, East, West, or Center.
comp-a Component object to be added to this layout manager.
public void removeLayoutComponent(Component comp)
removeLayoutComponent removes the specified component from the layout manager.
Parameters: comp-the Component object to be removed
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.
Parameters: target-a Container class containing components to be laid out.
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.
Parameters: target-a Container class containing components to be laid out.
public void layoutContainer(Container target)
layoutContainer will lay out the components contained in the target Container parameter. This method will reshape the components in the container based on the requirements of the border layout itself.
Parameters: target-a Container class containing components to be laid out.
public String toString()
toString returns a string representation of the BorderLayout class.
Returns: A String value containing the BorderLayout class's name plus its hgap and vgap values.
Extends: Component
A button can be placed on any type of layout because it derives directly from Component.
public Button()
This BUTTON constructor constructs a simple button with no text label.
public Button(String label)
This Button constructor constructs a simple button with a text label.
Parameters: label-a String value used to set the button's label.
public synchronized void addNotify()
addNotify sets the peer of the button using the function getToolkit.createButton. Using peer interfaces allows the user interface of the button to be changed without changing its functionality.
public String getLabel()
getLabel returns the button's label string.
Returns: A String value representing the button's label string.
public void setLabel(String label)
setLabel modifies the button's label string.
Parameters: label-a String value representing the button's new label string.
Extends: Component
A Canvas is used as a drawing surface for GUI applications.
public synchronized void addNotify()
addNotify sets the peer of the canvas using the function getToolkit.createCanvas. Using peer interfaces allows the user interface of the canvas to be changed without changing its functionality.
public void paint(Graphics g)
The paint method paints the canvas using the default background color (determine by calling getBackground).
Extends: Object
Implements: LayoutManager
The CardLayout class is a layout manager that allows the addition of "cards," only one of which may be visible at any given time. The user can "flip" through the cards.
public CardLayout()
This CardLayout constructor creates a new CardLayout layout manager.
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.
Parameters:
hgap-an integer value used to set the horizontal gap size.
vgap-an integer value used to set the vertical gap size.
public void addLayoutComponent(String name, Component comp)
addLayoutComponent adds a component to the card layout.
Parameters:
name-a string value that corresponds to the component's name.
comp-a Component object to be added to this layout manager.
public void removeLayoutComponent(Component comp)
removeLayoutComponent removes the specified component from the layout manager.
Parameters: comp-the Component object to be removed.
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.
Parameters: target-a Container class containing components to be laid out.
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.
Parameters: target-a Container class containing components to be laid out.
LayoutContainer
public void layoutContainer(Container parent)
layoutContainer will lay out the components contained in the target Container parameter. This method will reshape the components in the container based on the requirements of the border layout itself.
Parameters: target-a Container class containing components to be laid out.
public void first(Container parent)
The first method shows the first component in the card layout (the first card).
Parameters: parent-the parent Container class containing the components to be flipped through.
public void next(Container parent)
The next method shows the next component in the card layout (the next card).
Parameters: parent-the parent Container class containing the components to be flipped through.
public void previous (Container parent)
The previous method shows the previous component in the card layout (the previous card).
Parameters: parent-the parent Container class containing the components to be flipped through.
public void last(Container parent)
The last method shows the last component in the card layout (the last card).
Parameters: parent-the parent Container class containing the components to be flipped through.
public void show(Container parent, String name)
The show method flips to the component specified in the name parameter.
Parameters:
parent-the parent Container class containing the components to be flipped through.
name-a string value representing the name of the component to be displayed.
public String toString()
toString returns a string representation of the card layout class.
Returns: A String value containing the card layout class's name plus its hgap and vgap values.
Extends: Component
A Checkbox is a user interface component that is used to represent a true/false (or on/off)
value.
public Checkbox()
This Checkbox constructor constructs the simplest of all check boxes: one with no label, no group, and a false state value.
public Checkbox(String label)
This Checkbox constructor constructs a check box using the label parameter to set the check box's label. This check box will belong to no group and will be set to a false state value.
Parameters: label-a string value representing the check box's label.
public Checkbox(String label, CheckboxGroup group, boolean state)
This Checkbox constructor constructs a check box including the label, group, and initial value.
Parameters:
label-a string value representing the check box's label.
group-a CheckboxGroup object that this check box will be a member of.
state-the initial state value for this check box.
public synchronized void addNotify()
addNotify sets the peer of the check box using the function getToolkit.createCheckbox. Using peer interfaces allows the user interface of the check box to be changed without changing its functionality.
public String getLabel()
getLabel returns the check box's label string.
Returns: A String value representing the check box's label string.
public void setLabel(String label)
setLabel modifies the check box's label string.
Parameters: label-a String value representing the check box's new label string.
public boolean getState()
getState returns the check box's current state value.
Returns: A boolean value representing the check box's current state.
public void setState(boolean state)
setState sets the check box to the value represented by the state parameter.
Parameters: state-a boolean value containing the new value of the check box's state.
public CheckboxGroup getCheckboxGroup()
The getCheckboxGroup method returns the CheckboxGroup that this check box is a
member of.
Returns: A CheckboxGroup class that this check box is a member of.
public void setCheckboxGroup(CheckboxGroup g)
The setCheckboxGroup method is used to add this check box to a CheckboxGroup.
Parameters: g-a CheckboxGroup class to which this check box is to be added.
Extends: Object
A CheckboxGroup is used to group a set of Checkbox classes. When check boxes are created within a CheckboxGroup, only one check box may be selected at one time.
public CheckboxGroup()
This CheckboxGroup constructor constructs a CheckboxGroup instance with no check box members.
public Checkbox getCurrent()
The getCurrent method returns the current check box.
Returns: A Checkbox object representing the currently selected check box.
public synchronized void setCurrent(Checkbox box)
The setCurrent method sets the current check box in this CheckboxGroup.
Parameters: box-the Checkbox object that is to be made current.
public String toString()
toString returns a string containing Checkboxgroup information.
Returns: A string value containing the CheckboxGroup's name as well as the name of the currently selected check box.
Extends: MenuItem
A CheckboxMenuItem is a user interface component that can be added to a menu to represent a boolean value selection.
public CheckboxMenuItem(String label)
This CheckboxMenuItem constructor creates a CheckboxMenuItem with a text label containing the string passed in.
Parameters: label-a string value representing the label of the CheckboxMenuItem to be displayed.
public synchronized void addNotify()
addNotify sets the peer of the CheckboxMenuItem using the function getToolkit.createCheckboxMenuItem. Using peer interfaces allows the user interface of the CheckboxMenuItem to be changed without changing its functionality.
public boolean getState()
getState returns the state value of the CheckboxMenuItem's check box.
Returns: A boolean value representing the CheckboxMenuItem's check box state.
public void setState(boolean t)
setState is used to set the CheckboxMenuItem's check box state value.
Parameters: t-a boolean value representing the CheckboxMenuItem's check box state value.
public String paramString()
paramString returns a string containing CheckboxMenuItem information
Returns: A string value containing the CheckboxMenuItem's label as well as the state value of the CheckboxMenuItem's check box.
Extends: Component
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.
public Choice()
This Choice constructor creates a default Choice object that contains no information.
public synchronized void addNotify()
addNotify sets the peer of the Choice using the function getToolkit.createChoice. Using peer interfaces allows the user interface of the Choice to be changed without changing its functionality.
public int countItems()
countItems returns the number of items (or choices) that are available in this Choice object.
Returns: An integer value containing the number of items stored in this Choice object.
public String getItem(int index)
The getItem method returns the choice string at the index represented by the index value passed in.
Parameters: index-an integer value representing the index of the string item to be returned.
Returns: A String value representing the string at the index passed into this method.
public synchronized void addItem(String item)
addItem is used to add a String to a Choice object's internal list. The currently selected item will be displayed in the Choice object's pop-up menu.
Parameters: item-a String object containing a string to be added to the choice list.
Throws: NullPointerException if the string item to be added is null.
public String getSelectedItem()
getSelectedItem returns the string value of the currently selected item.
Returns: A String value containing the currently selected item's string.
public int getSelectedIndex()
getSelectedIndex returns the index of the currently selected item.
Returns: An integer value containing the index of the currently selected item.
public synchronized void select(int pos)
This select method selects the item at the position represented by the pos parameter.
Parameters: pos-an integer value representing the position of the item to be selected
Throws: IllegalArgumentException if the position value passed in is invalid.
public void select(String str)
This select method selects the item represented by the String parameter.
Parameters: str-a String value representing the string value of the choice to be selected.
Extends: Object
The Color class is provided to encapsulate RGB (red-green-blue) color 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.
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.
Parameters:
r-the red color value.
g-the green color value.
b-the blue color value.
public Color(int rgb)
This Color constructor creates a Color object based on the RGB color value passed in.
Parameters: rgb-an integer value containing the red, green, and blue color values that will be used to create this Color object.
public Color(float r, float g, float b)
This Color constructor create 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.
Parameters:
r-the red color value.
g-the green color value.
b-the blue color value.
public int getRed()
The getRed method returns the red component of this color.
Returns: An integer value representing this color's red component.
public int getGreen()
The getGreen method returns the green component of this color.
Returns: An integer value representing this color's green component.
public int getBlue()
The getBlue method returns the blue component of this color.
Returns: An integer value representing this color's blue component.
public int getRGB()
The getRGB method returns the RGB value of this color.
Returns: An integer value representing this color's RGB value in the default RGB color model.
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 approximately 1.4.
Returns: A Color object representing a brighter version of the current 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 approximately 1.4.
Returns: A Color object representing a darker version of the current color.
public int hashCode()
hashCode returns this color's hash code. This is useful when storing colors in a hash table.
Returns: An integer value representing this color's hash code.
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.
Parameters: obj-an Object object to be compared with this color.
Returns: A boolean value representing the result of the comparison of the Object parameter to this color.
public String toString()
toString returns a string representation of the Color class.
Returns: A String value containing the Color class's name plus its red, green, and blue values.
public static Color getColor(String nm)
getColor returns the specified color property based on the name that is passed in.
Parameters: nm-the name of the color property.
Returns: A Color value representing the desired color property.
public static Color getColor(String nm, Color v)
getColor returns the specified Color property of the specified color.
Parameters:
nm-the name of the color property.
v-the specified color to be examined.
Returns: A Color value representing the desired color property.
public static Color getColor(String nm, int v)
getColor returns the specified Color property of the color value that is passed in.
Parameters:
nm-the name of the color property.
v-the color value.
Returns: A Color value representing the desired color property.
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.
Parameters:
hue-the color's hue component.
saturation-the color's saturation component.
brightness-the color's brightness component.
Returns: An RGB value that corresponds to the HSB inputs.
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.
Parameters:
r-the color's red component.
g-the color's green component.
b-the color's blue component.
hsbvals-an array that will be used to store the HSB result values.
Returns: An array containing the resultant HSB values.
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.
Parameters:
h-the color's hue component.
s-the color's saturation component.
b-the color's brightness component.
Returns: A Color object representing the RGB value of the input hue, saturation, and brightness.
Extends: Object
Implements: ImageObserver
The Component class is used to represent a generic user interface component. All awt UI components derive from the Component class.
public Container getParent()
getParent returns this component's parent (a Container class).
Returns: A Container class representing the component's parent.
public ComponentPeer getPeer()
getPeer returns this component's peer (A ComponentPeer interface).
Returns: A ComponentPeer interface representing the component's peer.
public Toolkit getToolkit()
getToolkit returns the toolkit of this component. The toolkit is used to create the peer for the component.
Returns: A Toolkit class. A toolkit is required to bind the abstract awt classes to a native toolkit implementation.
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.
Returns: A boolean value representing the valid state of this 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.
Returns: A boolean value representing the visible state of this 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.
Returns: A boolean value representing the show state of this component.
public boolean isEnabled()
isEnabled determines whether this component is currently enabled. By default, components are enabled until told otherwise.
Returns: A boolean value representing the enabled state of this 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.
Returns: A Point object containing the location of the component.
public Dimension size()
size returns the current size of the component.
Returns: A Dimension object containing the size of the component.
public Rectangle bounds()
bounds returns the bounding rectangle of the component.
Returns: A Rectangle object containing the boundaries for the component.
public synchronized void enable()
The enable method is used to enable a component. When a component is disabled, it may be "grayed out" or simply not respond to user inputs.
public void enable(boolean cond)
This enable method is used to conditionally enable a component. When a component is disabled, it may be "grayed out" or simply not respond to user inputs.
Parameters: cond-a boolean value representing the new enabled state of the component.
public synchronized void disable()
The disable method disables a component. When a component is disabled, it may be "grayed out" or simply not respond to user inputs.
public synchronized void show()
show shows the component.
public void show(boolean cond)
This show method conditionally shows the component. If the input parameter is true, the component will be shown. If the input parameter is false, the component will be hidden.
Parameters: cond-a boolean value representing the new visible state of the component.
public synchronized void hide()
The hide method hides the component from view.
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.
Returns: A Color object representing the foreground color of this component.
public synchronized void setForeground(Color c)
setForeground sets the foreground color of the component.
Parameters: c-the new foreground color of this 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.
Returns: A Color object representing the background color of this component.
public synchronized void setBackground(Color c)
setBackground sets the background color of the component.
Parameters: c-the new background color of this 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.
public synchronized void setFont(Font f)
setFont sets the font of the component.
Parameters: f-the new font of this component.
public synchronized ColorModel getColorModel()
getColorModel gets the color model that will be used to display this component on an output device.
Returns: A ColorModel object representing the color model used by this component.
public void move(int x, int y)
The move method moves a component to a new location within its parent's coordinate space.
Parameters:
x-the new x coordinate of the component within its parent's coordinate space.
y-the new y coordinate of the component within its parent's coordinate space.
public void resize(int width, int height)
resize resizes the component to the specified width and height.
Parameters:
width-the new width size of the component.
height-the new height size of the component.
public void resize(Dimension d)
resize resizes the component to the specified dimension.
Parameters: d-a Dimension object representing the new size of the 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.
Parameters:
x-the new x coordinate of the component within its parent's coordinate space.
y-the new y coordinate of the component within its parent's coordinate space.
width-the new width size of the component.
height-the new height size of the component.
public Dimension preferredSize()
The preferredSize method returns the preferred size of the component.
Returns: A Dimension object representing the preferred size of the component.
public Dimension minimumSize()
minimumSize returns the minimum size of the component.
Returns: A Dimension object representing the minimum size of the component.
public void layout()
The layout method is called when the component needs to be laid out.
public void validate()
validate validates a component by calling its layout method.
public void invalidate()
invalidate invalidates a component, forcing the component and all parents above it to be laid out.
public Graphics getGraphics()
getGraphics returns a Graphics context for the component. If the component is not currently on the screen, this function will return null.
Returns: A Graphics object representing the component's graphics context.
public FontMetrics getFontMetrics(Font font)
getFontMetrics returns the current font metrics for a specified font. If the component is not currently on the screen, this function will return null.
Parameters: font-a Font object to be examined.
Returns: A FontMetrics object representing the component's font metrics.
public void paint(Graphics g)
The paint method paints the component on the screen using the Graphics context parameter.
Parameters: g-the Graphics context that the component will paint itself onto.
public void update(Graphics g)
The update method repaints the component in response to a call to the repaint method.
Parameters: g-the Graphics context that the component will paint itself onto.
public void paintAll(Graphics g)
The paintAll method is used to paint the component along with all of its subcomponents.
Parameters: g-the Graphics context that the component will paint itself onto.
public void repaint()
repaint is used to force a component to repaint itself. Calling this function will result in a call to repaint.
public void repaint(long tm)
This repaint method is used to force a component to repaint itself in tm milliseconds.
Parameters: tm-the time span, in milliseconds, from the time this function was called that the component will repaint itself.
public void repaint(int x, int y, int width, int height)
This repaint method will force the component to repaint part of its surface area based on the input coordinates.
Parameters:
x-the x coordinate marking the surface area to be repainted.
y-the y coordinate marking the surface area to be repainted.
width-the width of the surface area to be repainted.
height-the height of the surface area to be repainted.
public void repaint(long tm, int x, int y, int width, int height)
This repaint method will force the component to repaint part of its surface area based on the input coordinates at a specified time in the future.
Parameters:
tm-the time, in milliseconds, from the time this method was called that the component will need to repaint itself.
x-the x coordinate marking the surface area to be repainted.
y-the y coordinate marking the surface area to be repainted.
width-the width of the surface area to be repainted.
height-the height of the surface area to be repainted.
public void print(Graphics g)
print prints the component using the Graphics context. The default implementation of this method calls paint.
Parameters: g-the Graphics context to be printed on.
public void printAll(Graphics g)
printAll prints the component and all of its subcomponents using the Graphics context.
Parameters: g-the Graphics context to be printed on.
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.
Parameters:
img-an Image object to be examined for changes.
flags-a flags parameter contains imaging flags such as FRAMEBITS, ALLBITS, and SOMEBITS.
x-the x coordinate marking the surface area to be repainted.
y-the y coordinate marking the surface area to be repainted.
width-the width of the surface area to be repainted.
height-the height of the surface area to be repainted.
Returns: A boolean value that is true if the image has changed, false if not.
public Image createImage(ImageProducer producer)
createImage creates an Image using the specified image producer.
Parameters: producer-an ImageProducer interface that will be used to produce a new image.
Returns: An Image object.
createImage
public Image createImage(int width, int height)
This createImage creates an offscreen Image object using the specified width and height. This Image object can be used for things like double buffering.
Parameters:
width-the width of the Image object to be created.
height-the height of the Image object to be created.
Returns: An Image object.
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.
Parameters:
image-an Image object that will be rendered on this component.
observer-an Observer interface that will be notified when the Image is ready to be rendered.
Returns: A boolean value that is true if the image has been prepared, false if not.
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.
Parameters:
image-an Image object that will be rendered on this component.
width-the width of the image to be rendered.
height-the height of the image to be rendered.
observer-an Observer interface that will be notified when the Image is ready to be rendered.
Returns: A boolean value that is true if the image has been prepared, false if not.
public int checkImage(Image image, ImageObserver observer)
checkImage checks the status of the construction of the image to be rendered.
Parameters:
image-an Image object that will be rendered on this component.
observer-an Observer interface that will be notified when the Image is ready to be rendered.
Returns: An integer value that is the boolean OR of the ImageObserver flags for the data that is currently available.
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.
Parameters:
image-an Image object that will be rendered on this component.
width-the width of the image to be checked.
height-the height of the image to be checked.
observer-an Observer interface that will be notified when the image is ready to be rendered.
Returns: An integer value that is the boolean OR of the ImageObserver flags for the data that is currently available.
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.
Parameters:
x-the x coordinate to be examined.
y-the y coordinate to be examined.
Returns: A boolean value representing the result of the coordinate check.
public Component locate(int x, int y)
locate returns the Component at the specified x and y coordinates.
Parameters:
x-the x coordinate to be examined.
y-the y coordinate to be examined.
Returns: The Component that is found at the specified x and y coordinates.
public void deliverEvent(Event e)
deliverEvent delivers an event to the component.
Parameters: e-an Event object encapsulating the event.
public boolean postEvent(Event e)
postEvent posts an event to the component resulting in a call to handleEvent.
Parameters: e-an Event object encapsulating the event.
Returns: A boolean value that is true if the event was handled, false if not.
public boolean handleEvent(Event evt)
handleEvent is used to handle individual events by the component.
Parameters: evt-an Event object encapsulating the event.
Returns: A boolean value that is true if the event was handled, false if not.
public boolean mouseDown(Event evt, int x, int y)
The mouseDown method is called if the mouse is down.
Parameters:
evt-an Event object encapsulating the event.
x-the x coordinate of the mouse down click point.
y-the y coordinate of the mouse down click point.
Returns: A boolean value that is true if the event was handled, false if not.
public boolean mouseDrag(Event evt, int x, int y)
The mouseDrag method is called if the mouse is dragged.
Parameters:
evt-an Event object encapsulating the event.
x-the x coordinate of the current mouse point coordinate.
y-the y coordinate of the current mouse point coordinate.
Returns: A boolean value that is true if the event was handled, false if not.
public boolean mouseUp(Event evt, int x, int y)
The mouseUp method is called when the mouse button is let up.
Parameters:
evt-an Event object encapsulating the event.
x-the x coordinate of the mouse up point.
y-the y coordinate of the mouse up point.
Returns: A boolean value that is true if the event was handled, false if not.
public boolean mouseMove(Event evt, int x, int y)
The mouseMove method is called if the mouse is moved.
Parameters:
evt-an Event object encapsulating the event.
x-the x coordinate of the current mouse point coordinate.
y-the y coordinate of the current mouse point coordinate.
Returns: A boolean value that is true if the event was handled, false if not.
public boolean mouseEnter(Event evt, int x, int y)
The mouseEnter method is called if the mouse enters the component.
Parameters:
evt-an Event object encapsulating the event.
x-the x coordinate of the current mouse point coordinate.
y-the y coordinate of the current mouse point coordinate.
Returns: A boolean value that is true if the event was handled, false if not.
public boolean mouseExit(Event evt, int x, int y)
The mouseExit method is called if the mouse exits the component.
Parameters:
evt-an Event object encapsulating the event.
x-the x coordinate of the mouse exit point.
y-the y coordinate of the mouse exit point.
Returns: A boolean value that is true if the event was handled, false if not.
public boolean keyDown(Event evt, int key)
The keyDown method is called when a key is pressed.
Parameters:
evt-an Event object encapsulating the event.
key-an integer value representing the code of the key that was pressed.
Returns: A boolean value that is true if the event was handled, false if not.
public boolean keyUp(Event evt, int key)
The keyUp method is called when a key is let up.
Parameters:
evt-an Event object encapsulating the event.
key-an integer value representing the code of the key that was pressed.
Returns: A boolean value that is true if the event was handled, false if not.
public boolean action(Event evt, Object what)
The action method is called if an action occurs within the component.
Parameters:
evt-an Event object encapsulating the event.
what-an object representing the action that is occurring.
Returns: A boolean value that is true if the event was handled, false if not.
public void addNotify()
addNotify notifies a component to create a peer object.
public synchronized void removeNotify()
removeNotify notifies a component to destroy the peer object.
public boolean gotFocus(Event evt, Object what)
The gotFocus method is called when the component receives the input focus.
Parameters:
evt-an Event object encapsulating the event.
what-an object representing the action that is occurring.
Returns: A boolean value that is true if the event was handled, false if not.
public boolean lostFocus(Event evt, Object what)
The lostFocus method is called when the component loses the input focus.
Parameters:
evt-an Event object encapsulating the event.
what-an object representing the action that is occurring.
Returns: A boolean value that is true if the event was handled, false if not.
public void requestFocus()
The requestFocus method requests the current input focus. If this method is successful, gotFocus will then be called.
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.
public String toString()
toString returns a string representation of the Component class.
Returns: A String value containing the Component class's name plus its x, y, height, and width values.
public void list()
The list method prints a listing of the component to the print stream.
public void list(PrintStream out)
This list method prints a listing of the component to the specified output stream.
Parameters: out-a PrintStream object.
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.
Parameters:
out-a PrintStream object.
indent-an integer value representing the amount to be indented.
Extends: Component
A Container class is defined as a class that can contain other components.
countComponents
public int countComponents()
countComponents returns the number of components contained within the container.
Returns: An integer value representing the number of components within the container.
public synchronized Component getComponent(int n)
The getComponent method returns the component at the specified index.
Parameters: n-an integer value representing the index at which to retrieve a component.
Returns: A Component object within the container.
public synchronized Component[] getComponents()
getComponents returns an array of Component objects contained within the Container.
Returns: An array of Component objects contained within the container.
public Insets insets()
The insets methods returns the borders of this container.
Returns: An Insets object representing the insets of the 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.
Parameters: comp-the component to be added.
Returns: The Component object that was added to the container's list.
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.
Parameters:
comp-the component to be added.
pos-the position the component is to be added at.
Returns: The Component object that was added to the container's list.
public synchronized Component add(String name, Component comp)
This add method adds a Component using the Component argument and that Component's name.
Parameters:
name-a String representing the name of the component.
comp-the component to be added.
Returns: The Component object that was added to the container's list.
public synchronized void remove(Component comp)
The remove method removes the specified component from the Container's list.
Parameters: comp-the component to be removed.
public synchronized void removeAll()
The removeAll method removes all components from within the Container.
public LayoutManager getLayout()
getLayout returns this container's layout manager.
Returns: A layout manager interface representing the container's LayoutManager.
public void setLayout(LayoutManager mgr)
setLayout sets the current layout manager of the container.
Parameters: mgr-the layout manager that will control the layouts of this Container's components.
public synchronized void layout()
The layout method is called to perform a layout on this component.
public synchronized void validate()
The validate method refreshes the container and all of the components within it by validating the container and all of its components.
public synchronized Dimension preferredSize()
preferredSize returns the preferred size of this container.
Returns: A Dimension object representing the preferred size of this Container.
public synchronized Dimension minimumSize()
minimumSize returns the minimum size of this container.
Returns: A Dimension object representing the minimum size of this Container.
public void paintComponents(Graphics g)
The paintComponents method is used to paint each of the components within the container.
Parameters: g-the Graphics context that the container's components will be painted on.
public void printComponents(Graphics g)
The printComponents method is used to print each of the components within the container.
Parameters: g-the Graphics context that the container's components will be printed on.
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.
Parameters: e-the event to be delivered.
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.
Parameters:
x-the x coordinate of the component to be located.
y-the y coordinate of the component to be located.
public synchronized void addNotify()
addNotify notifies the container to create a peer interface. This method will also notify each of the container's components to do likewise.
public synchronized void removeNotify()
removeNotify notifies the container to remove its peer. This method will also notify each of the container's components to do likewise.
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.
Parameters:
out-a PrintStream object.
indent-an integer amount representing the value to indent the list.
Extends: Window
The Dialog class is used to create a window that can be closed by the user. Dialogs are normally temporary windows that are used for inputting information.
public Dialog(Frame parent, boolean modal)
This Dialog constructor constructs a Dialog object from a parent Frame object. This dialog is initially invisible.
Parameters:
parent-the parent frame of the dialog.
modal-a boolean value designating this dialog to be either modal or nonmodal.
public Dialog(Frame parent, String title, boolean modal)
This Dialog constructor constructs a Dialog object from a parent Frame object. This dialog is initially invisible.
Parameters:
parent-the parent frame of the dialog.
title-a String value representing the title to be displayed for this dialog.
modal-a boolean value designating this dialog to be either modal or nonmodal.
public synchronized void addNotify()
The addNotify method creates the dialog's peer. Making use of a peer interface allows the dialog's appearance to be changed without changing its functionality.
public boolean isModal()
isModal returns the modal status of the dialog.
Returns: A boolean value representing the dialog's modal status. If this is true, the dialog is modal. If false, the dialog is nonmodal.
public String getTitle()
getTitle returns the dialog's title string.
Returns: A String value representing the title string of the dialog.
public void setTitle(String title)
The setTitle method sets the dialog's title string.
Parameters: title-a String value representing the dialog's new title.
public boolean isResizable()
The isResizable method is called to determine whether or not this dialog can be resized.
Returns: A boolean value that is true if the dialog is resizable, false if it is not.
public void setResizable(boolean resizable)
The setResizable method is used to change whether a dialog can be resized.
Parameters: resizable-a boolean value that is true if the dialog is to be resizable and false if not.
Extends: Object
A Dimension class is used to encapsulate an object's height and width.
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.
public Dimension()
This Dimension constructor constructs an empty Dimension object.
public Dimension(Dimension d)
This Dimension constructor constructs a Dimension object from an existing Dimension object.
Parameters: d-a Dimension object whose values will be used to create the new dimension.
public Dimension(int width, int height)
This Dimension constructor constructs a Dimension object based on the width and height input parameters.
Parameters:
width-an integer value representing the width of the new dimension.
height-an integer value representing the height of the new dimension.
public String toString()
The toString method is used to return a string representation of this Dimension object.
Returns: A String containing this dimension's height and width values.
Extends: Object
The Event class is used to encapsulate GUI event's in a platform-independent manner.
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 keypress 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.Member 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 time stamp 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.
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 will be 0. It will be 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 will be stored in an array or linked list.
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 and modifiers, and some argument.
Parameters:
target-the target object for the event.
when-the time stamp for the event.
id-the event type.
x-the x coordinate of the event.
y-the y coordinate of the event.
key-the key pressed that triggered a keyboard event.
modifiers-the state of the modifier keys.
arg-an arbitrary argument.
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.
Parameters:
target-the target object for the event.
when-the time stamp for the event.
id-the event type.
x-the x coordinate of the event.
y-the y coordinate of the event.
key-the key pressed that triggered a keyboard event.
public Event(Object target, int id, Object arg)
This Event constructor constructs an event using the target, event ID, and some argument.
Parameters:
target-the target object for the event.
id-the event type.
arg-an arbitrary argument.
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 will translate the coordinates to make sense for that particular component.
Parameters:
x-the x coordinate.
y-the y coordinate.
public boolean shiftDown()
The shiftDown method returns the current state of the Shift key.
Returns: A boolean value that is true if the Shift key is down, false if it is up.
public boolean controlDown()
The controlDown method returns the current state of the Ctrl key.
Returns: A boolean value that is true if the Ctrl key is down, false if it is up.
public boolean metaDown()
The metaDown method returns the current state of the Meta key.
Returns: A boolean value that is true if the meta key is down, false if it is up.
public String toString()
The toString method returns the string representation of the current event.
Returns: A String value containing information on the event, including the id, x, y, key, shiftDown, controlDown, and metaDown values.
Extends: Dialog
A FileDialog is presented to a user in order for that user to select a file. This dialog is a modal dialog, therefore the calling thread will be blocked until this dialog exits.
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.
public FileDialog(Frame parent, String title)
This FileDialog constructor constructs a file dialog using a parent frame and a title string.
Parameters:
parent-the parent frame of the file dialog.
title-a String containing the dialog's title.
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.
Parameters:
parent-the parent frame of the file dialog.
title-a String containing the dialog's title.
mode-an integer value representing the dialog mode (LOAD or SAVE).
public synchronized void addNotify()
addNotify notifies FileDialog to create a peer. Using a peer interface allows the user interface of the file dialog to be changed without changing its functionality.
public int getMode()
getMode returns the current mode of the file dialog.
Returns: An integer value representing the current mode (LOAD or SAVE) of the file dialog.
public String getDirectory()
The getDirectory method returns the current directory of the file dialog.
Returns: A String value representing FileDialog's current directory.
public void setDirectory(String dir)
The setDirectory method is used to set the current directory of the FileDialog.
Parameters: dir-a String value representing the directory to be set.
public String getFile()
The getFile method returns the currently selected file within FileDialog.
Returns: A String value representing the file dialog's current file.
public void setFile(String file)
The setFile method is used to set the current file of the file dialog.
Parameters: file-a String value representing the file to be set.
Extends: Object
Implements: LayoutManager
A FlowLayout implements the LayoutManager interface. This class is used to lay out buttons from left to right until no more buttons fit on the Panel.
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.
public FlowLayout()
This FlowLayout constructor constructs a default FlowLayout class with a centered alignment.
public FlowLayout(int align)
This FlowLayout constructor constructs a FlowLayout class using the specified alignment.
Parameters: align-the alignment value (LEFT, CENTER, or RIGHT).
public FlowLayout(int align, int hgap, int vgap)
This FlowLayout constructor constructs a FlowLayout class using the specified alignment and gap values.
Parameters:
align-the alignment value (LEFT, CENTER, or RIGHT).
hgap-the horizontal gap value.
vgap-the vertical gap value.
public void addLayoutComponent(String name, Component comp)
The addLayoutComponent method adds a component to the FlowLayout class.
Parameters:
name-a String value representing the name of the Component to be added.
comp-the Component object to be added to FlowLayout.
public void removeLayoutComponent(Component comp)
removeLayoutComponent removes a component from the FlowLayout class.
Parameters: comp-a Component object to be removed from FlowLayout.
public Dimension preferredLayoutSize(Container target)
The preferredLayoutSize method returns the preferred size for this FlowLayout given the components in the specified container.
Parameters: target-a Container object that will be examined to determine the preferred layout size for this FlowLayout.
Returns: A Dimension class containing the preferred size of the FlowLayout.
public Dimension minimumLayoutSize(Container target)
The minimumLayoutSize method returns the minimum size for this FlowLayout given the components in the specified container.
Parameters: target-a Container object that will be examined to determine the minimum layout size for this FlowLayout.
Returns: A Dimension class containing the minimum size of the FlowLayout.
public void layoutContainer(Container target)
The layoutContainer method lays out the components within the specified container.
Parameters: target-a Container class containing a set of components that will be laid out according to the FlowLayout rules.
public String toString()
The toString method returns a string representation of the FlowLayout class.
Returns: A String containing information about the FlowLayout, including the FlowLayout's name, alignment, hgap, and vgap values.
Extends: Object
This class is used to encapsulate a font.
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.
public Font(String name, int style, int size)
The Font constructor constructs a font of the specified name, style, and size.
Parameters:
name-the name of the font to be created.
style-the style (PLAIN and/or BOLD and/or ITALIC) of the font to be created.
size-the size of the font to be created.
public String getFamily()
getFamily returns the font family that this font belongs to.
Returns: A String value representing the font's family name.
public String getName()
getName returns the name of the Font object.
Returns: A String value representing the name of the font.
public int getStyle()
getStyle returns the style of the Font object.
Returns: An integer value representing the style of the font.
public int getSize()
getSize returns the size of the Font object.
Returns: An integer value representing the point size of the font.
public boolean isPlain()
isPlain returns the plain style state of the Font.
Returns: A boolean value that is true if the font is plain, false if not.
public boolean isBold()
isBold returns the bold style state of the Font.
Returns: A boolean value that is true if the font is bold, false if not.
public boolean isItalic()
isItalic returns the italic style state of the Font.
Returns: A boolean value that is true if the font is italic, false if not.
public static Font getFont(String nm)
getFont returns a Font based on the system properties list and the name passed in.
Parameters: nm-the name of the font to be returned from the system properties list.
Returns: A Font object based on the system properties list.
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.
Parameters:
nm-the name of the font to be returned from the system properties list.
font-the default font to be returned if the font specified by the nm variable is not found.
Returns: A Font object based on the system properties list.
public int hashCode()
hashCode returns a hash code for this font.
Returns: An integer value representing the hash code for the font.
public boolean equals(Object obj)
equals compares an object with the Font object.
Parameters: obj-the object to compare the font with.
Returns: A boolean value that is true if the objects are equal, false if not.
public String toString()
The toString method is used to return a string representation of the font.
Returns: A String value containing the font family, name, style, and size values.
Extends: Object
The FontMetrics class is used to encapsulate a FontMetrics object containing font information.
public Font getFont()
The getFont method returns the font that these FontMetrics refer to.
Returns: A Font object.
public int getLeading()
The getLeading method gets the line spacing of the font.
Returns: 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.
public int getAscent()
The getAscent method gets the ascent value for a font.
Returns: An integer value containing the ascent value for a font. This value is the distance from the bottom of a character to its top.
public int getDescent()
The getDescent method gets the descent value for a font.
Returns: An integer value containing the descent value for a font. This value is the bottom coordinate of a character.
public int getHeight()
The getHeight method gets the height of a line of text using the current Font.
Returns: An integer value containing the height of a line of text. This value is calculated by adding the ascent, descent, and leading values.
public int getMaxAscent()
getMaxAscent returns the maximum value of a font's ascent.
Returns: An integer value containing the maximum value of a font's ascent for all of that
font's characters.
public int getMaxDescent()
getMaxDescent returns the maximum value of a font's descent.
Returns: An integer value containing the maximum value of a font's descent for all of that font's characters.
public int getMaxDecent()
The getMaxDecent method is provided only for backward compatibility. It simply calls the getMaxDescent method.
Returns: An integer value containing the maximum value of a font's descent for all of that font's characters.
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.
public int charWidth(int ch)
charWidth returns the width of a particular character for the current font.
Parameters: ch-an integer value representing the character to be checked.
Returns: An integer value representing the width of the specified character.
public int charWidth(char ch)
This charWidth method returns the width of a particular character for the current font.
Parameters: ch-a string value representing the character to be checked.
Returns: An integer value representing the width of the specified character.
public int stringWidth(String str)
The stringWidth method returns the width of a specified string using the current font.
Parameters: str-a string representing the characters to be checked.
Returns: An integer value representing the advance width of the specified string.
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.
Parameters:
data-an array of characters to be checked.
off-an integer value representing the offset into the array where the string will start.
len-the number of characters to be measured.
Returns: An integer value representing the advance width of the specified string.
public int bytesWidth(byte data[], int off, int len)
The bytesWidth method returns the width of a specified array of bytes
Parameters:
data-an array of bytes to be checked.
off-an integer value representing the offset into the array where the string will start.
len-the number of bytes to be measured.
Returns: An integer value representing the advance width of the specified string.
public int[] getWidths()
The getWidths method gets the advance widths of the first 256 characters of the font.
Returns: An integer array containing the advance widths of the first 256 characters of the font.
public String toString()
The toString method is used to return a string representation of the FontMetrics class.
Returns: A String value containing the font metrics' name, font, ascent, descent, and height.
Extends: Window
Implements: MenuContainer
A Frame class represents a basic window.
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.
public Frame()
The Frame constructor constructs a default frame that is invisible and that uses the BorderLayout layout manager.
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.
Parameters: title-a String value containing the frame's title string.
public synchronized void addNotify()
The addNotify method creates a peer interface for the frame. Peer interfaces allow the user interface of the frame to be changed without changing its functionality.
public String getTitle()
getTitle returns the frame's title.
Returns: A String value representing the title of the frame.
public void setTitle(String title)
setTitle sets the frame's title.
Parameters: title-a String value representing the title of the frame.
public Image getIconImage()
The getIconImage method returns an image representing the iconized image of the frame.
Returns: An Image class representing the iconized image of the frame.
public void setIconImage(Image image)
setIconImage is used to set the image that will be used when the frame is iconized.
Parameters: image-an Image class that will be displayed when the frame is iconized.
public MenuBar getMenuBar()
The getMenuBar method returns the MenuBar object that is contained within this frame.
Returns: A MenuBar class that is displayed within this frame.
public synchronized void setMenuBar(MenuBar mb)
setMenuBar sets the MenuBar class to be displayed within the frame.
Parameters: mb-a MenuBar object to be used for the frame's menu bar.
public synchronized void remove(MenuComponent m)
The remove method removes the specified MenuComponent from the frame.
Parameters: A MenuComponent object that is to be removed from the 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.
public boolean isResizable()
The isResizable method returns the frame's resizable state.
Returns: A boolean value that is true if the frame can be resized, false if not.
public void setResizable(boolean resizable)
The setResizable method sets the frame's resizable state.
Returns: A boolean value that is true if the frame can be resized, false if not.
public void setCursor(int cursorType)
The setCursor method sets the cursor to be displayed within the frame.
Returns: An integer value representing the cursor to be displayed, which can be any of the frame's static values such as WAIT_CURSOR, MOVE_CURSOR, and so on.
public int getCursorType()
The getCursorType method returns the frame's current cursor type.
Returns: An integer value representing the current cursor type for the frame.
Extends: Object
The Graphics class represents the base class for all types of graphics contexts.
public abstract Graphics create()
This abstract function creates a new Graphics object.
public Graphics create(int x, int y, int width, int height)
The create method creates a new Graphics object using the specified parameters.
Parameters:
x-the x coordinate of the graphics context.
y-the y coordinate of the graphics context.
width-the width of the graphics context.
height-the height of the graphics context.
Returns: A Graphics class corresponding to the create method's specifications.
public abstract void translate(int x, int y)
The translate method translates the Graphics object to the new x and y origin coordinates.
Parameters:
x-the new x origin coordinate.
y-the new y origin coordinate.
public abstract Color getColor()
The getColor method returns the current color.
Returns: A Color object representing the current color used for drawing operations.
public abstract void setColor(Color c)
The setColor method sets the current color.
Parameters: c-a Color object to be used for graphics drawing operations.
public abstract void setPaintMode()
The setPaintMode method sets the paint mode to overwrite the destination with the current color.
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 will be changed to the specified color c1 and vice versa.
Parameters: c1-the Color object specified to be XOR'd with the current color.
public abstract Font getFont()
The getFont method returns the current font used for the graphics context.
Returns: A Font object representing the graphics context's current font.
public abstract void setFont(Font font)
The setFont method sets the graphics context's font.
Parameters: A Font object that will be used as the current font.
public FontMetrics getFontMetrics()
The getFontMetrics method will return the font metrics for the current font.
Returns: A FontMetrics object representing the font metrics for the current font.
public abstract FontMetrics getFontMetrics(Font f)
This getFontMetrics method will return the font metrics for the specified font.
Returns: A FontMetrics object representing the font metrics for the specified font.
public abstract Rectangle getClipRect()
The getClipRect method will return the current clipping rectangle for the Graphics class.
Returns: A Rectangle object representing the current clipping rectangle.
public abstract void clipRect(int x, int y, int width, int height)
The clipRect method will set the current clipping rectangle for the Graphics class.
Parameters:
x-the x coordinate of the clipping rectangle.
y-the y coordinate of the clipping rectangle.
width-the width of the clipping rectangle.
height-the height of the clipping rectangle.
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.
Parameters:
x-the x coordinate of the region to be copied.
y-the y coordinate of the region to be copied.
width-the width of the region to be copied.
height-the height of the region to be copied.
dx-the horizontal distance of the region to be copied to.
dy-the vertical distance of the region to be copied to.
drawLine
public abstract void drawLine(int x1, int y1, int x2, int y2)
The drawLine method will draw a line on the graphics context from one point to another point specified by the input parameters.
Parameters:
x1-the x coordinate of the line's starting point.
y1-the y coordinate of the line's starting point.
x2-the x coordinate of the line's ending point.
y2-the y coordinate of the line's ending point.
public abstract void fillRect(int x, int y, int width, int height)
The fillRect method fills the specified rectangular region with the current color.
Parameters:
x-the x coordinate of the rectangle to be filled.
y-the y coordinate of the rectangle to be filled.
width-the width of the rectangle to be filled.
height-the height of the rectangle to be filled.
drawRect
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.
Parameters:
x-the x coordinate of the rectangle to be drawn.
y-the y coordinate of the rectangle to be drawn.
width-the width of the rectangle to be drawn.
height-the height of the rectangle to be drawn.
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.
Parameters:
x-the x coordinate of the rectangle to be cleared.
y-the y coordinate of the rectangle to be cleared.
width-the width of the rectangle to be cleared.
height-the height of the rectangle to be cleared.
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.
Parameters:
x-the x coordinate of the rectangle to be drawn.
y-the y coordinate of the rectangle to be drawn.
width-the width of the rectangle to be drawn.
height-the height of the rectangle to be drawn.
arcWidth-the horizontal diameter of the arc at the four corners.
arcHeight-the vertical diameter of the arc at the four corners.
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.
Parameters:
x-the x coordinate of the rectangle to be drawn.
y-the y coordinate of the rectangle to be drawn.
width-the width of the rectangle to be drawn.
height-the height of the rectangle to be drawn.
arcWidth-the horizontal diameter of the arc at the four corners.
arcHeight-the vertical diameter of the arc at the four corners.
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.
Parameters:
x-the x coordinate of the rectangle to be drawn.
y-the y coordinate of the rectangle to be drawn.
width-the width of the rectangle to be drawn.
height-the height of the rectangle to be drawn.
raised-a boolean value determining whether the rectangle is raised.
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.
Parameters:
x-the x coordinate of the rectangle to be drawn.
y-the y coordinate of the rectangle to be drawn.
width-the width of the rectangle to be drawn.
height-the height of the rectangle to be drawn.
raised-a boolean value determining whether the rectangle is raised.
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.
Parameters:
x-the x coordinate of the rectangle to draw the oval within.
y-the y coordinate of the rectangle to draw the oval within.
width-the width of the rectangle to draw the oval within.
height-the height of the rectangle to draw the oval within.
fillOval
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.
Parameters:
x-the x coordinate of the rectangle to draw the oval within.
y-the y coordinate of the rectangle to draw the oval within.
width-the width of the rectangle to draw the oval within.
height-the height of the rectangle to draw the oval within.
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 and bounded by the specified input coordinates. Note that 0 degrees represents the three o'clock position and that positive angles are measured going counterclo