- Using Visual J++ -

Chapter 19

Visual J++ Applet and AWT Class Reference


This chapter presents material differently from the chapters that come before it. This chapter fills in many of the missing holes by describing some details of the pre-defined Visual J++ Applet and AWT classes, data members, and methods. The chapter works as a mini-reference guide to the Applet and AWT pre-defined classes. As stated in this book's introduction, you'll use this chapter as a reference guide as you progress through your Visual J++ programming experiences.

The Class Packages

Visual J++ provides a rich collection of pre-defined class packages. Throughout this book, you've seen several of the more important packages. As you'll recall, a class package contains several pre-defined classes and a class can contain both pre-defined data constants and methods. Here are the class packages Visual J++ provides:

This chapter concentrates only on the first two, Java.applet and Java.awt, because those are the classes covered in the most detail in this book. If you want to use methods or named constants from these class packages, you generally use the import command to import the class package. For example, to use the init() method, you must import the Java.applet class package like this:

import java.applet.*; // Imports all the class data and methods

Instead of importing the entire package, you can import just the specific class. The heading of each of this chapter's tables contains the specific class that contains the methods that the table describes. For example, you will see that the drawString() method appears in the java.awt.Graphics class. Therefore, either of the following import commands let you use the drawString() method in the rest of the program:

import java.awt.*; // Imports the entire class package

import java.awt.Graphics; // Imports only one class from the package

You do not have to import the Java.lang class specifically to use the methods defined there.

 
Keep your eyes open for additional class packages you can obtain online or from software companies. Check out some of Appendix B's Web sites for potential class locations. These class packages provide additional functionality to the standard class packages described here.
 
 
Each of the class methods described in the following tables contain a prototype method. A prototype is a format that describes the method's parameters and return data types. From the prototype (listed before each method's description) you will be able to determine how to format the method for your own programs. Remember that if a prototype does not contain a return data type or any parameters, no return value or parameters appear when you use the method.

This chapter does not contain a complete class package reference. Visual J++ includes many more methods and named constants than those described here. This chapter's class package tables explain the more common pre-defined class data and methods from the Applet and AWT class packages, which are the class packages that interest most newcomers to Visual J++ and Java.

Check Visual J++'s Books Online (Visual J++'s online help reference material) for the complete list of pre-defined class package data and methods. As you read through these class descriptions, you'll run across class methods and named constants that you may want to use in your own applets. Now that you've mastered the basics needed for using Visual J++, you can add these class methods to your applets to increase the power of your applets and Web sites. As you begin to develop more comprehensive applets, you may want to explore the other class packages not detailed here, such as the networking class package.

The java.applet.Applet Class

You use the java.applet.Applet class for all your primary applet creation and standard operation.

Class Method Prototype and Description
Applet Applet()
Creates a new applet. You will always inherit your applet from this method.
destroy destroy()
Removes the current applet as well as its resources from memory.
getAppletContext appletContext getAppletContext()
Lets the applet retrieve system environment information.
getAppletInfo String getAppletInfo()
Returns the applet's author, version, and other applet information you set up from the new applet wizard.
getAudioClip AudioClip getAudioClip(URL [, String])
Returns the audio clip (a sound file) at the URL and (optionally) a string value with the audio clip's name.
getCodeBase URL getCodeBase()
Returns the applet's URL.
getDocumentBase URL getDocumentBase()
Returns the URL of the HTML page in which the applet resides.
getParameter String getParameter(String)
Returns the applet's parameter given the applet's String-based name.
getParameterInfo String[][] getParameterInfo()
Returns a string array containing each of the applet's parameters.
init init()
The method a Java-based program automatically executes right after your applet constructs. Java calls init() the first time Java executes the start() method.
isActive boolean isActive()
Returns a boolean value that represents whether or not the applet is active yet (the applet is not active until the start() method).
play play(URL [, String])
Plays the audio clip at the URL and returns the audio's name if available.
resize resize([Dimension] [int, int])
Resizes the applet's borders to the special dimension or, if supplied, to the width and height values specified by the two integer parameters respectively.
showStatus showStatus(String)
Displays the String inside the applet's content window.
start start()
The method a Java-based program automatically executes upon initial execution.
stop stop()
The method a Java-based program automatically executes before the applet terminates.

The Abstract java.applet.AppletContext Class

Each of these class methods is abstract; therefore, you must supply overriding methods so that your derived classes are usable and not abstract also. Use the java.applet.AppletContext class to get information about the browser running the current applet.

Class Method Prototype and Description
getApplet abstract Applet getApplet(String)
Returns the name of the applet.
showDocument abstract void showDocument(URL)
Displays the document located at the URL.
showStatus abstract void showStatus(String)
Displays the String message in the Applet's context window.

The Abstract java.applet.AudioClip Class

Each of these class methods is abstract; therefore, you must supply overriding methods so that your derived classes are usable and not abstract also. You can derive from this class to play audio files.

Class Method Prototype and Description
loop abstract void loop()
Plays the audio clip continuously.
play abstract void play()
Plays an audio clip.
Stop abstract void stop()
Stops playing the audio clip if the clip is still in progress.

The java.awt.BorderLayout Class

Use the java.awt.BorderLayout class to place container items (the Windows-like controls) in North, South, East, West, and Center screen regions.

Class Method Prototype and Description
BorderLayout BorderLayout([int, int])
Constructs a border layout with (optionally) a horizontal and vertical gap in points.
addLayoutComponent void addLayoutComponent(String, Component)
Adds the component (such as a button or text box) to the location (for example, South) specified by the string.
minimumLayoutSize Dimension minimumLayoutSize(Container)
Call to receive the minimum necessary dimensions of the specified container.
removeLayoutComponent void removeLayoutComponent(Component)
Removes the component from the layout.

The java.awt.Button Class

Use the java.awt.Button class to place and manipulate button components.

Class Method Prototype and Description
Button Button([String])
Constructs a new button with (optionally) the string's label.
getLabel String getLabel()
Returns the string value of the label's text.
setLabel void setLabel(String)
Sets the button's label to the string.

The java.awt.Canvas Class

Use the java.awt.Canvas class to place and manipulate button components.

Class Method Prototype and Description
Canvas Canvas()
Constructs a canvas surface for your drawings.
paint void paint(Graphics)
Paints the current canvas with your drawing. Generally, you inherit from this class and add your own paint() method.

The java.awt.CardLayout Class

Use the java.awt.CardLayout class to place and manipulate tabbed property sheet dialog boxes.

Class Method Prototype and Description
CardLayout CardLayout([int, int])
Constructs a new card layout (property sheet) with the optional horizontal and vertical point sized gaps on each edge.
addLayoutComponent void addLayoutComponent(String, Component)
Adds the component to the card layout dialog box and names the component with the string value.
first void first(Container)
Activates the first card (the "top" property sheet).
last void last(Container)
Activates the last card (the "bottom" property sheet).
minimumLayoutSize Dimension minimumLayoutSize(Container)
Call to receive the minimum necessary dimensions of the specified container.
next void next(Container)
Activates the next card (the "next" property sheet) within the card layout.
preferredLayoutSize Dimension preferredLayoutSize(Container)
Call to receive the recommended necessary dimensions of the specified container.
previous void previous(Container)
Activates the previous card (the "former" property sheet) within the card layout.
removeLayoutComponent void removeLayoutComponent(Component)
Removes the component from the layout.
show void show(Container, String)
Displays the component indicated by the string in the specified container.

The java.awt.CheckBox Class

Use the java.awt.CheckBox class to place and manipulate boolean check boxes.

Class Method Prototype and Description
Checkbox Checkbox(String [, CheckboxGroup, boolean])
Constructs a new check box with the string label inside (optionally) the group specified. If you include a group, also include the check box's checked or unchecked state with true or false.
getCheckboxGroup CheckboxGroup getCheckboxGroup()
Call to receive the check box's group name.
getLabel String getLabel()
Returns the string value of the check box's text.
getState boolean getState()
Returns the boolean value of the check box's checked or unchecked state.
setCheckboxGroup void setCheckboxGroup(CheckboxGroup)
Sets the group for the current check box.
setLabel void setLabel(String)
Sets the check box's label to the string.
setState void setState(boolean)
Sets the check box to checked or unchecked depending on the true or false value inside the boolean parameter.

The java.awt.CheckBoxMenuItem Class

Use the java.awt.CheckBoxMenuItem class to place a check box item on a menu option.

Class Method Prototype and Description
CheckboxMenuItem CheckboxMenuItem(String)
Constructs a new check box item on the menu with the label indicated by the string. The check box menu item is initially unchecked (turned off).
getState boolean getState()
Call to receive the menu item's check box state.
setState void setState(boolean)
Sets the menu's check box to checked or unchecked depending on the true or false value inside the boolean parameter.

The java.awt.Choice Class

Use the java.awt.Choice class to place a pop-up menu on your applet.

Class Method Prototype and Description
Choice Choice()
Constructs a new pop-up choice menu.
addItem void addItem(String)
Adds a new item with the string's label to the pop-up choice menu.
countItems int countItems()
Call to receive the number of items on the pop-up choice menu.
getItem String getItem(int)
Call to receive the label of the item indicated by the integer index parameter.
getSelectedIndex int getSelectedIndex()
Call to receive the index of the pop-up menu's selected choice.
getSelectedItem String getSelectedItem()
Call to receive the label of the pop-up menu's selected choice.
select void select(int)
Selects the pop-up menu choice indicated by the integer index.
select void select(String)
Selects the pop-up menu choice indicated by the string label.

The java.awt.Color Class

Use the java.awt.Color class to control the colors you want in your AWT objects. You can use the following named constants to indicate common specific colors:

Use the following methods to construct and work with colors. The colors are called RGB colors due to their combinations of red, green, and blue combinations.

Class Method Prototype and Description
Color Color(int, int, int)
Constructs a color with the amount of red, green, and blue components indicated by the three integer parameters respectively. The parameters can range from 0 to 255.
Color Color(float, float, float)
Constructs a color with the amount of red, green, and blue components indicated by the three floating-point parameters respectively. The parameters can range from 0.0 to 1.0 indicating the percentage of red, green, and blue color amounts.
Color Color(int)
Constructs a color given the Windows-based RGB integer value.
brighter Color brighter()
Brightens the color.
darker Color darker ()
Darkens the color.
equals boolean equals(Object)
Call to determine if the object is the same color as the current color setting.
getBlue int getBlue()
Call to receive the integer portion of the color's blue amount.
getGreen int getGreen()
Call to receive the integer portion of the color's green amount.
getRed int getRed()
Call to receive the integer portion of the color's red amount.
getRGB int getRGB()
Call to receive the integer RGB combination value of the current color.

The java.awt.Component Class

Use the java.awt.Component class to manipulate an AWT component, or object, such as a button or text box, that appears on your applet's container area.

Class Method Prototype and Description
action boolean action(Event, Action)
Java automatically calls the action() method when the event triggers the specified action. If you want to handle the action, do so and return true; if you return false (or choose not to handle one or more events or actions), the default AWT handler takes over.
deliverEvent void deliverEvent(Event)
Sends the event to the current component or to a subclassed component.
disable void disable()
Disables the component from operation.
enable void enable()
Enables a disabled component.
enable void enable(boolean)
Enables a disabled component if the boolean value is true and disables a component if the boolean value is false.
getBackground Color getBackground()
Call to get the current background color of the current component.
getFont Font getFont()
Call to receive the font used in the component.
getFontMetrics FontMetrics getFontMetrics(Font)
Call to receive font information about the specified font.
getForeground Color getForeground()
Call to receive the component's foreground color.
getGraphics Graphics getGraphics()
Call to receive the component's graphics context if the component appears on the screen and returns null otherwise.
getParent Container getParent()
Call to receive the parent container.
gotFocus void gotFocus()
Your applet automatically calls this method when the component gets the focus (the highlight to receive keyboard input).
handleEvent boolean handleEvent(Event)
Your applet automatically calls this method when the event occurs. When you want to handle a particular event, override this method by returning true; return false if you want the default event handler to intercept the event.
hide void hide()
Turns the component invisible.
inside boolean inside(int, int)
Call to determine if your x- and y-coordinates, indicated by the two integer parameters respectively, fall within the component's area.
invalidate void invalidate()
Invalidates the current component.
isEnabled boolean isEnabled()
Call to find out if the current component is enabled.
isShowing boolean isShowing()
Call to find out if the current component is enabled or disabled.
isValid void isValid()
Call to find out if the current component is valid or invalid.
isVisible boolean isVisible()
Call to find out if the current component is visible or hidden.
keyDown boolean keyDown(Event, int)
Your applet calls this method if the event is triggered by the specific integer keypress.
keyUp boolean keyUp(Event, int)
Your applet calls this method if the event is triggered by the specific integer key release.
layout void layout()
Sets up the layout for this component.
locate Component locate(int, int)
Call to receive the component located at the x- or y-coordinate.
location Point location()
Call to receive the current x- and y-coordinate location of this component.
lostFocus void lostFocus()
Your applet calls this method when the current component loses its focus.
mouseDown boolean mouseDown(event, int, int)
Your applet calls this method when the mouse button is pressed at the coordinate location indicated by the two integer parameters.
mouseDrag boolean mouseDrag(event, int, int)
Your applet calls this method when the mouse is dragged at the coordinate location indicated by the two integer parameters.
mouseEnter boolean mouseEnter(event, int, int)
Your applet calls this method when the mouse is moved into the coordinate location indicated by the two integer parameters.
mouseExit boolean mouseExit(event, int, int)
Your applet calls this method when the mouse is moved out of the coordinate location indicated by the two integer parameters.
mouseMove boolean mouseMove(event, int, int)
Your applet calls this method when the mouse is moved at the coordinate location indicated by the two integer parameters.
mouseUp boolean mouseUp(event, int, int)
Your applet calls this method when the mouse button is released at the coordinate location indicated by the two integer parameters.
move void move(int, int)
Moves the component to the integer x- and y-locations.
nextFocus void nextFocus()
Moves the component focus to the next focus in the container.
paint void paint(Graphics)
Paints the component on the graphics context.
paintAll void paintAll(Graphics)
Paints the component and all child components on the graphics context.
postEvent void postEvent(Event)
Forces the specified event so that the handleEvent() method is called.
prepareImage boolean prepareImage(Image, [int, int,] ImageObserver)
Prepares the image for viewing on the current component and returns a true value when the image is ready. Specify the two integer width and height parameters if you want to use those values for the image.
print void print(Graphics)
Prints the current component in the graphics context.
printAll void printAll(Graphics)
Prints the current component and all child components in the graphics context.
repaint void repaint(long)
Automatically calls the update method as soon as Java can redraw the component or at least before the long integer millisecond value.
resize void resize(int, int)
Changes the size of the current component to the integer x- and y-coordinates.
setBackground void setBackground(Color)
Sets the current component's background color.
setFont void setFont(Font)
Sets the current component's font.
setForeground void setForeground(Color)
Sets the current component's foreground color.
show void show()
Shows the current component.
show void show(boolean)
Shows the current component if the boolean value is true.
size Dimension size()
Call to receive the size of the current component.
update void update(Graphics)
Updates the component (but not the background) when the repaint() method executes.
validate void validate()
Validates the current component.

The java.awt.Container Class

Use the java.awt.Container class to manipulate an AWT container that holds one or more components.

Class Method Prototype and Description
add Component add(Component, int)
Adds the component to the current container at the integer index position. If the integer index is -1, the component appears at the end of the container.
add Component add([String,] Component)
Adds the component to the current container and adds the container at the optional string specified location (such as "West").
countComponents int countComponents()
Call to receive the number of components in the current container.
deliverEvent void deliverEvent(Event)
Sends the event to the current container's component that can receive the event.
getComponent Component getComponent(int)
Call to receive the component located at the integer index position inside the current container.
getComponents Component[] getComponent()
Call to receive every component into an array.
locate Component locate(int, int)
Call to receive the component located at the integers' x- and y-coordinates.
paintComponents void paintComponents(Graphics)
Paints the components on the graphics context.
remove void remove(Component)
Removes the specified component from the current container.
removeAll void removeAll()
Removes every specified component from the current container.
setLayout void setLayout(LayoutManager)
Sets the current container's layout.
validate void validate()
Validates the current container.

The java.awt.Dialog Class

Use the java.awt.Dialog class to create and manipulate an AWT dialog box.

Class Method Prototype and Description
Dialog Dialog(Frame [, String], boolean)
Constructs the new dialog box with the optional string for the title. The frame indicates the dialog box's parent and whether or not the parent is modal (true), meaning the dialog box will intercept all input, or not modal (false), if other events can intercept the keystrokes.
getTitle String getTitle()
Call to receive the dialog box's title.
isModal boolean isModal()
Call to determine if the dialog box is modal or not.
isResizable boolean isResizable()
Call to determine if the dialog box is resizable.
setResizable void setResizable(boolean)
Call to let the user set the dialog box's size (if true) or to keep the user from setting the dialog box's size (if false).
setTitle void setTitle(String)
Adds a new string title to the current dialog box.

The java.awt.Event Class

Use the java.awt.Event class to control AWT container events. The most important member elements of this class are the named constants that represent possible events shown here:

Use the following methods to construct and work with events.

Class Method Prototype and Description
controlDown boolean controlDown()
Call to determine if the user pressed the Ctrl key.
metaDown boolean metaDown()
Call to determine if the user pressed the designated meta key (a key that triggers a command).
shiftDown boolean shiftDown()
Call to determine if the user pressed the Shift key.
translate void translate(int, int)
Determines the event at the location specified by the integer x- and y-coordinates.

The java.awt.FileDialog Class

Use the java.awt.FileDialog class to control Windows-like file selection dialog boxes. You can use the following named constants for testing the two primary file-related events:

Use the following methods to construct and work with file-related dialog boxes.

Class Method Prototype and Description
getDirectory String getDirectory()
Call to receive the selected directory within the file dialog box.
getFile String getFile()
Call to receive the selected file within the file dialog box.
getFilenameFilter String getFilenameFilter()
Call to receive the selected file-name filter (such as *.txt or *.html within the file dialog box.
getMode String getMode()
Call to receive the load or save state of the file dialog box (use the named constants for testing).
setDirectory void setDirectory(String)
Call to set the file dialog box's directory to the string parameter.
setFile void setFile(String)
Call to set the file dialog box's file to the string parameter.
setFilenameFilter void setFilenameFilter(FileNameFilter)
Call to set the file dialog box's file-name wildcard filter to the specified parameter.

The java.awt.FlowLayout Class

Use the java.awt.FlowLayout class to control the layout of the containers on which you place your AWT components. You can use the following named constants for determining the components' layout flow:

Use the following methods to construct the flow layouts. A few flow layout container manipulation methods exist, but they are not covered here.

Class Method Prototype and Description
FlowLayout FlowLayout([int])
Constructs a flow layout container with the optional alignment specified (use the named constants).
FlowLayout FlowLayout(int, int, int)
Constructs a flow layout container with the integer alignment, integer horizontal gap, and integer vertical point gap (the space between components).

The java.awt.Font Class

Use the java.awt.Font class to define and change the font used with components. The following data members help you control the fonts you use:

Use the following methods to construct and manipulate your fonts.

Class Method Prototype and Description
Font Font(String, int, int)
Constructs the specified font style from the string name with the specified integer style and integer point sizes.
equals boolean equals(Object)
Use to see if the object's font is equal to the current object's font.
getFamily String getFamily()
Call to receive the current font's family name.
getFont Font getFont(String [, Font])
Returns the font given the string's property. If getFont() can find no matching font, the system returns the default font that you optionally specify.
getName String getName()
Returns the current font's name.
getSize String getSize()
Returns the current font's size.
getStyle String getStyle()
Returns the current font's style.
isBold boolean isBold()
True if the current font is boldfaced.
isItalic boolean isItalic()
True if the current font is italicized.
isPlain boolean isPlain()
true if the current font is a plain font with no special formatting.

The java.awt.FontMetrics Class

Use the java.awt.FontMetrics class to define and change the font metrics used with components. The font metrics describe a font's size and statistics.

Class Method Prototype and Description
FontMetrics FontMetrics(Font)
Constructs the specified font metrics-defined component.
charWidth int charWidth(char)
Returns the integer point size of the specified character.
getAscent int getAscent()
Returns the integer point size of the character's height above the font's baseline.
getDescent int getDescent()
Returns the integer point size of the character's height below the font's baseline.
getFont Font getFont()
Call to receive the name of the current font.
getHeight Font getHeight()
Call to receive the height of the current font.
getLeading Font getLeading()
Call to receive the current font's full height.
getMaxAdvance int getMaxAdvance()
Call to receive the maximum advance point width for the font's characters.
getMaxAscent int getMaxAscent()
Call to receive the maximum point size ascent value for the font's largest characters.
getMaxDescent int getMaxDescent()
Call to receive the maximum point size descent value for the font's largest characters.
getWidths int [] getWidths()
Call to receive an integer array of the 256 ASCII characters.
stringWidth int stringWidth(String)
Call to receive the width of the string you specify.

The java.awt.Frame Class

Use the java.awt.Frame class to define and change a window. The window frame is initially invisible and has no title. The following data members help you control the fonts you use:

Use the following methods to construct and manipulate frames.

Class Method Prototype and Description
Frame Frame([String])
Constructs a new frame with the optional title.
dispose void dispose()
Releases the frame's resources and gets rid of the frame. Call this method when you finish with the frame.
getCursorType int getCursorType()
Call to receive the cursor type that you can test with the pre-defined named cursor constants.
getIconImage Image getIconImage()
Call to receive the frame's icon.
getMenuBar MenuBar getMenuBar()
Call to receive the frame's menu bar.
getTitle String getTitle()
Call to receive the frame's title.
isResizable boolean isResizable()
Informs you if the frame is resizable.
remove void remove(MenuComponent)
Removes the menu from the frame.
setCursor void setCursor(int)
Changes the cursor to the integer cursor definition (use the pre-defined cursor named constants).
setIconImage void setIconImage(Image)
Specifies the frame's icon that appears when the user minimizes the frame.
setmenuBar void setMenuBar(MenuBar)
Specifies which menu bar goes with the current frame.
setResizable void setResizable(boolean)
Specifies whether or not the end-user can resize the frame.
setTitle void setTitle(String)
Specifies the frame's title.

The java.awt.Graphics Class

Use the java.awt.Graphics class to create and manipulate your applet's graphic elements.

Class Method Prototype and Description
clearRect abstract void clearRect(int, int, int, int)
Fills the rectangle region specified by the integer x-coordinate, y-coordinate, width, and height parameters with the background color, effectively erasing the rectangle.
copyArea abstract void copyArea(int, int, int, int, int, int)
Copies the area specified by the first four integer parameters (the x-coordinate, y-coordinate, width, and height parameters) to the final two integer x- and y-coordinates.
create abstract Graphics create([int, int, int, int])
Makes a copy of the current graphics object. If you specify the optional x-coordinate, y-coordinate, width, and height parameters, the copy is made based on these parameters.
dispose abstract void dispose()
Eliminates the current graphics object.
draw3DRect void draw3DRect(int, int, int, int, boolean)
Draws a 3D rectangle using the x-coordinate, y-coordinate, width, and height parameters, and raises the rectangle if the boolean parameter is true.
drawArc abstract void drawArc(int, int, int, int, int, int)
Draws an arc whose center falls in the first two integer parameters x- and y-coordinates with the size specified by the third and fourth integer width and height parameters. The arc draws from the start angle indicated by the fifth argument to the final argument (indicated in degrees).
drawChars void drawChars(char [], int, int, int, int)
Draws the characters located in the character array. The second argument indicates the offset of the starting array character to draw and the third parameter indicates the length of the array. The last two parameters indicate the x- and y-coordinates.
drawImage abstract boolean drawImage(Image, int, int [, int, int], ImageObserver)
Draws the image at the x- and y-coordinates indicated by the second and third parameters. The optional parameters determine the width and height if you want to specify those values. The ImageObserver notifies you once the image is completely drawn.
drawImage abstract boolean drawImage(Image, int, int [, int, int], Color, ImageObserver]
Augments the previous drawImage() method by specifying the image's color.
drawLine abstract void drawLine(int, int, int, int)
Draws a line from the first two integer coordinates to the last two integer coordinates.
drawOval abstract void drawOval(int, int, int, int)
Draws an oval inside an imaginary rectangle specified by the four integer coordinates.
drawPolygon abstract void drawPolygon(int[], int[], int)
Draws a multi-sided figure using the multiple coordinates specified by the two integer array parameters for the number of points specified by the final parameter.
drawPolygon abstract void drawPolygon(Polygon)
Draws a polygon based on the polygon parameter's characteristics.
drawRect void drawRect(int, int, int, int)
Draws a rectangle at the first two integer coordinates with the width and height point values specified by the last two parameters.
drawRoundRect void drawRoundRect(int, int, int, int, int, int)
Draws a rounded rectangle at the first two integer coordinates with the width and height point values specified by the last two parameters. The final two parameters indicate the arc's width and height values for the rounded corners.
drawString abstract void drawString(String, int, int)
Draws the indicated string starting at the integer coordinates.
fill3DRect void fill3DRect(int, int, int, int, boolean)
Paints a 3D rectangle using the drawRect() coordinates using the current color.
fillArc abstract void fillArc(int, int, int, int, int, int)
Paints an arc using the drawArc() coordinates using the current color.
fillOval abstract void fillOval(int, int, int, int)
Paints an oval using the drawOval() coordinates using the current color.
fillPolygon abstract void fillPolygon(int[], int[], int)
Paints a polygon using the drawPolygon() coordinates using the current color.
fillRect abstract void fillRect(int, int, int, int)
Paints a rectangle using the drawRect() coordinates using the current color.
fillRoundRect abstract void fillRoundRect(int, int, int, int, int, int)
Paints a rounded rectangle using the drawRoundRect() coordinates using the current color.
finalize void finalize()
Calls the current graphics context dispose() method, which eliminates the graphics context when you are finished with the context.
getColor abstract Color getColor()
Call to receive the current color.
getFont abstract Font getFont()
Call to receive the current font.
getFontMetrics abstract FontMetrics getFontMetrics()
Call to receive the current font's metrics.
getFontMetrics abstract FontMetrics getFontMetrics(Font)
Call to receive the font parameter's font metrics.
setColor abstract setColor(Color)
Sets the current color to the color parameter.
setFont abstract setFont(Font)
Sets the current font to the font parameter.

The java.awt.Image Class

Use the java.awt.Image class to create and manipulate your applet's graphic images.

Class Method Prototype and Description
flush abstract void flush()
Eliminates all resources used by the current image.
getGraphics abstract Graphics getGraphics()
Call to receive a graphics object to draw into the current offscreen image.
getheight abstract int getHeight(ImageObserver)
Call to receive th height, in pixels, of the current image. If the image is not yet defined, getHeight() returns -1 and the ImageObserver is notified at the completion of the image.
getSource Abstract ImageProducer getSource()
Call to receive the image producer for the current image's pixels.
getWidth abstract int getWidth(ImageObserver)
Call to receive the width, in pixels, of the current image. If the image is not yet defined, getWidth() returns -1 and the ImageObserver is notified at the completion of the image.

The java.awt.Label Class

Use the java.awt.Label class to create and manipulate your applet's labels. Use the following alignment named constants for aligning your label captions:

Use the following methods to create and manipulate labels.

Class Method Prototype and Description
Label Label()
Constructs a new and empty label.
Label Label(String [, int])
Constructs a new label with the string caption and optional alignment value.
getAlignment int getAlignment()
Call to receive the current label's alignment.
getText String getText()
Call to receive the current label's caption.
setAlignment void setAlignment(int)
Call to specify the current label's alignment. Use the named alignment constants.
setText void setText(String)
Call to specify the current label's caption.

The java.awt.Label Class

Use the java.awt.Label class to create and manipulate your applet's labels. Use the following methods to create and manipulate labels.

Class Method Prototype and Description
List List([int, boolean])
Constructs a scrolling list with the optional integer parameter's rows and allows for multiple selections (using Ctrl+Click) if you specify the optional boolean true parameter.
addItem void addItem(String, int)
Adds the string item to the list at the integer's index.
allowsMultipleSelections boolean allowsMultipleSelections()
Call to see if the current list lets the user select from multiple entries.
clear void clear()
Erases the current list's contents.
countItems int countItems()
Call to receive the total number of items in the list.
delItem void delItem(int)
Deletes the integer parameter's indexed item from the current list.
delItems void delItems(int, int)
Deletes the current list's items from the first parameter's index to the second parameter's index value.
deselect void deselect(int)
Deselects a selected item at the integer index.
getItem void getItem(int)
Call to get the item at the integer index.
getRows int getRows()
Call to receive the number of rows currently showing in the current list.
getSelectedIndex int getSelectedIndex()
Call to receive the currently selected item's index (getSelectedIndex() returns -1 if no items are selected).
getSelectedIndexes int [] getSelectedIndexes()
Call to receive all the indexes for the items currently selected (getSelectedIndex() returns -1 if no items are selected) for multiple selection lists.
getSelectedItem Sting getSelectedItem()
Call to receive the currently selected item (getSelectedItem() returns null if no items are selected).
getSelectedItems String [] getSelectedItems()
Call to receive all the items currently selected (getSelectedItems() returns null if no items are selected) for multiple selection lists.
getVisibleIndex int getVisibleIndex()
Call to receive the most recently-made visible item.
isSelected boolean isSelected(int)
Call to determine if the integer parameter's indexed item is selected.
makeVisible void makeVisible(int)
Brings the indexed item into view.
replaceItem void replaceItem(String, int)
Call to replace the item indicated by the integer index with the new item's string parameter.
select void select(int)
Selects the item at the integer parameter's index.
setMultipleSelections void setMultipleSelections(boolean)
Call to determine if the list will allow for multiple selections.

The java.awt.Menu Class

Use the java.awt.Menu class to create and manipulate your applet's menus that drop down from the menu bar. Use the following methods to create and manipulate your menus.

Class Method Prototype and Description
Menu Menu(String [, boolean])
Constructs a menu with the specified string title. If you supply a true boolean parameter, the menu is a tear-off menu, meaning that the menu remains on the screen after the user releases the mouse button.
add MenuItem add(MenuItem)
Adds an item to the current menu.
add void add(String)
Adds a new item with the string value to the current menu.
addSeparator void addSeparator()
Adds a menu separator bar to the menu.
countItems int countItems()
Call to receive the number of items in the menu.
getItem MenuItem getItem(int)
Call to receive the menu item located at the integer parameter's menu index.
isTearOff boolean isTearOff()
Call to determine if the menu is a tear-off menu.
remove void remove(int)
Removes the selected integer parameter's indexed item.
remove void remove(MenuComponent)
Removes the selected menu component from the current menu.

The java.awt.MenuBar Class

Use the java.awt.MenuBar class to create and manipulate your applet's menu bars. Use the following methods to create and manipulate your menu bars.

Class Method Prototype and Description
MenuBar MenuBar()
Constructs a new menu bar that is unattached to any frame.
add Menu add(Menu)
Adds an item to the current menu bar.
countMenus int countItems()
Call to receive the number of items in the menu bar.
getHelpMenu Menu getHelpMenu()
Call to receive the current menu bar's help menu.
getMenu Menu getMenu(int)
Call to receive the integer index's menu bar item's menu.
remove void remove(int)
Removes the selected integer parameter's indexed item from the current menu bar.
remove void remove(MenuComponent)
Removes the selected menu component from the current menu bar.
setHelpMenu void setHelpMenu(Menu)
Indicates which menu is the Help menu on the current menu bar.

The java.awt.MenuItem Class

Use the java.awt.MenuItem class to create and manipulate your applet's individual menu items. Use the following methods to create and manipulate your menu items.

Class Method Prototype and Description
MenuItem MenuItem(String)
Constructs a new menu item, labeled with the string parameter.
disable void disable()
Disables, or grays out, the current menu item.
enables void enable([boolean])
Enables, or activates, the current menu item. Use the optional boolean parameter to disable or enable the item.
getLabel String getLabel()
Call to receive the current menu item's label.
isEnabled boolean isEnabled()
Call to determine if the current menu item is enabled or disabled.
setLabel void setLabel(String)
Adds the string parameter's label to the menu item.

The java.awt.Point Class

Use the java.awt.Point class to create and manipulate your applet's graphics points. The AWT class supports the following variables that define the coordinates of the given point:

Use the following methods to create and manipulate your graphics points.

Class Method Prototype and Description
Point Point(int, int)
Constructs a new point at the integer parameter's coordinates.
equals boolean equals(Object)
Determines if the current point and the object appear at the same coordinate.
move void move(int, int)
Moves the current point to the new integer parameter coordinates.

The java.awt.Polygon Class

Use the java.awt.Polygon class to create and manipulate your applet's graphics polygons (multi-sided figures). The AWT class supports the following variables that define the coordinates of the given polygon:

Use the following methods to create and manipulate your graphics polygons.

Class Method Prototype and Description
Polygon Polygon(int [], int [], int)
Constructs a new polygon at the integer parameter's coordinate array pairs with the number of points specified by the third parameter.
addPoint void addPoint(int, int)
Adds a point to the current polygon.
inside boolean inside(int, int)
Call to determine if the specified coordinate point falls with the polygon's region.

The java.awt.Rectangle Class

Use the java.awt.Rectangle class to create and manipulate your applet's graphics rectangles. The AWT class supports the following variables that define the coordinates of the given rectangle:

Use the following methods to create and manipulate your graphics rectangles.

Class Method Prototype and Description
Rectangle Rectangle([int, int])
Constructs a rectangle with the optional coordinates.
Rectangle Rectangle(int, int, int, int)
Constructs a rectangle with the coordinates and the width and height specified by the last two integer parameters.
Rectangle Rectangle(Dimension)
Constructs a rectangle from the dimension passed.
add void add(int, int)
Adds a point to the current rectangle so that the rectangle has to grow to envelope the point as well as the rectangle's original size.
equals boolean equals(Object)
Call to see if the current rectangle is equal to the object's dimensions.
grow void grow(int, int)
Grows the current rectangle to twice the size of the passed coordinates while keeping the original center of the rectangle.
inside boolean inside(int, int)
Call to determine if the specified coordinate point falls with the rectangle's region.
intersects boolean intersects(Rectangle)
Call to see if the current rectangle intersects the passed rectangle.
move void move(int, int)
Moves the current rectangle to the passed coordinate pair.
reshape void reshape(int, int, int, int)
Reshapes the current rectangle to the passed x- and y-coordinates with the width and height specified by the last two integer parameters.

The java.awt.ScrollBar Class

Use the java.awt.Scrollbar class to create and manipulate your applet's graphics scrollbars. The AWT class supports the following variables that define the scrollbar:

Use the following methods to create and manipulate your scrollbars.

Class Method Prototype and Description
Scrollbar Scrollbar([int])
Constructs a scrollbar with the passed orientation (use a named constant).
Scrollbar Scrollbar(int, int, int, int, int)
Constructs a scrollbar with the passed orientation, an initial value, the integer point size of the scrollbar, and the maximum and minimum scrollbar values.
getLineIncrement int getLineIncrement()
Call to receive the current scrollbar's line increment.
getMaximum int getMaximum()
Call to receive the current scrollbar's maximum value.
getMinimum int getMinimum()
Call to receive the current scrollbar's minimum value.
getOrientation int getOrientation()
Call to receive the current scrollbar's horizontal or vertical orientation.
getPageIncrement int getPageIncrement()
Call to receive the current scrollbar's page increment value.
getValue int getValue()
Call to receive the current scrollbar's current value.
getVisible int getVisible()
Call to receive the current scrollbar's visible value.
setLineIncrement void setLineIncrement(int)
Specifies the scrollbar's line increment (the amount that scrolls when the user clicks the up or down arrow).
setPageIncrement void setPageIncrement(int)
Specifies the scrollbar's page increment (the amount that scrolls when the user clicks inside the scrollbar's shaft).
setValue void setValue(int)
Sets the current scrollbar's value.
setValues void setValues(int, int, int, int)
Sets these scrollbar values: current value set, the visible amount, the minimum value, and the maximum value.

The java.awt.TextArea Class

Use the java.awt.TextArea class to create and manipulate your applet's text areas. Use the following methods to create and manipulate your text areas.

Class Method Prototype and Description
TextArea TextArea([int, int])
Constructs the text area with the optional number of character columns and rows.
TextArea TextArea(String, [int, int])
Constructs the text area with an initial string value and sets to the optional number of character columns and rows.
appendText void appendText(String)
Adds the string to the end of the current text area.
getColumns int getColumns()
Call to receive the text area's columns.
getRows int getRows()
Call to receive the text area's rows.
insertText void insertText(String, int)
Inserts the string at the integer parameter's index position within the text area.
replaceText void replaceText(String, int, int)
Replaces the text area's text with the string, starting at the second parameter's index position and ending with the third parameter's index position.

The java.awt.Component Class

Use the java.awt.Component class to create and manipulate your applet's text-editing capabilities within text boxes and text areas. Use the following methods to create and manipulate your applet's text-editing capabilities.

Class Method Prototype and Description
getSelectedText String getSelectedText()
Call to receive the currently selected text.
getSelectionEnd int getSelectionEnd()
Call to receive the currently selected text's ending index.
getSelectionStart int getSelectionStart()
Call to receive the currently selected text's starting index.
getText String getText()
Call to receive the selected text.
isEditable boolean isEditable()
Call to determine if the current text is editable.
select void select(int, int)
Select the text beginning at the first parameter's index position and ending with the second parameter's index position.
selectAll void selectAll()
Selects all the text in the text component.
setEditable void setEditable(boolean)
Specifies that the current text component is editable or not.
setText void setText(String)
Places the string text in the current text component.

The java.awt.TextField Class

Use the java.awt.TextField class to create and manipulate your applet's editable text boxes. Use the following methods to create and manipulate your applet's text boxes.

Class Method Prototype and Description
TextField TextField([int])
Constructs a new text box that has the optional number of columns.
TextField TextField(String [, int])
Constructs a new text box with the string label defined to have the optional number of columns.
getColumns int getColumns()
Call to receive the number of columns in the text box.

The java.awt.Window Class

Use the java.awt.Window class to create and manipulate your applet's windows. Use the following methods to create and manipulate your applet's windows.

Class Method Prototype and Description
Window Window(Frame)
Constructs a new modal window frame that is initially invisible.
dispose void dispose()
Destroys the window frame and releases its resources.
show void show()
Displays the current window frame.
toBack void toBack()
Sends the current window frame to the back of the window stacks.
toFront void toFront()
Brings the current window frame to the front of the window stacks.

Summary

The goal of this chapter was to list the methods and data members you may want to use from the Applet and AWT class packages. Although you may not have a need for every method discussed, this chapter does give you a reference for studying sample Java code that you view on the Internet and inside the Visual J++ sample applets.

This chapter concludes this book, but not your Visual J++ mastery. We hope that we have met and surpassed your expectations for this book; that is, we hope that you now have the tools you need to understand Visual J++'s basics, to know where Java fits into the picture, and to write your own Java-enabled Web sites with Visual J++.

Here are the points this chapter covered:

You can use this chapter as a reference while continuing to hone your Visual J++ skills. When you run across a class that contains a method you don't understand, or when you need to draw a particular shape and don't know the methods needed, look to this chapter for a description of the class that performs the job.


Previous Page TOC Next Page

| Previous Chapter | Next Chapter |

| Table of Contents | Book Home Page |

| Que Home Page | Digital Bookshelf | Disclaimer |


To order books from QUE, call us at 800-716-0044 or 317-361-5400.

For comments or technical support for our books and software, select Talk to Us.

© 1996, QUE Corporation, an imprint of Macmillan Publishing USA, a Simon and Schuster Company.