CATEGORII DOCUMENTE |
Asp | Autocad | C | Dot net | Excel | Fox pro | Html | Java |
Linux | Mathcad | Photoshop | Php | Sql | Visual studio | Windows | Xml |
This chapter introduces the concepts behind the peer interfaces of the Java Abstract Windowing Toolkit (AWT). As a Java application developer you will never need to use any of the peer classes. The interfaces described in this chapter will be of interest mainly to programmers who are porting the Java Development Kit (JDK) to a new operating system. This introduction gives you an insight into the object-oriented design of the peer interfaces and describes how they help reduce the effort needed to port the Java AWT to another operating system.
The individual characteristics of the graphics toolkits supported on different operating systems make the task of implementing a portable windowing toolkit difficult. Separating the user's perspective on the windowing abstraction from the operating system's perspective poses a problem that involves a lot of programming effort when moving the toolkit from one platform to another. If the actual implementation of the toolkit is decoupled from the user's perspective, then porting the toolkit as a whole is a lot simpler, as only the implementation module has to be changed to support the new operating system platform. The peer interfaces of the Java AWT do exactly that. They decouple the abstractions of the AWT classes (such as Button, List, Label, and so on) from their implementation on a specific windowing platform (such as the Windows95 operating system or the Motif windowing toolkit available on Unix systems).
The appearance of a graphical user interface component differs from toolkit to toolkit. The common problem faced with developing applications using the windowing toolkits available today is that the user has to relearn the look and feel of the graphical components when the application is run on a different platform. The Java design team designed the AWT in such a way that the graphical components would preserve the look-and-feel of the underlying operating system's native windowing toolkit. This is one reason why Java has been accepted as a language for cross-platform application development.
Figure 9-1 shows two views of a Java application that includes a label, a button, and a checkbox. The window on the left shows the application running on the Windows95 operating system and the one on the right shows the same application running on the Solaris operating system (using the Motif windowing toolkit).
Figure 9-1 The same AWT application running on Windows95 and
on Solaris (Motif windowing toolkit)
The GUI-specific code is encapsulated in the classes that implement the peer interface. These peer classes serve as the interface between the AWT classes such as Component, Button, Label, Container, and so on, and the underlying operating system's graphics primitives. The AWT classes do not communicate directly with the native windowing toolkit. They create a peer object that serves as a channel of communication between the AWT class and the native windowing toolkit. Each instance of a class (such as Button) is associated with an instance of the corresponding peer class (such as ButtonPeer). In order to port the Java AWT to a windowing toolkit, only the peer interfaces have to be implemented. The higher level of abstraction such as the Component, Button, or List class need not change at all. Figure 9-2 shows where the peer interfaces fit into the overall Java AWT model.
Figure 9-2 The role of peers in the AWT system model
Each of the peer interfaces described in this chapter has to be implemented to create a GUI-dependent class that performs the task required of the peer. The code for these methods is written in the C language, using the graphics primitives of the native windowing toolkit. Chapter 3 on the Toolkit class and Appendix C on writing native code for Java, provide more information regarding the specifics of implementing native code for a target windowing system.
Due to the licensing issues involved with modifying the source code of the Java Development Kit, this chapter does not contain a project implementation and there are no example entries for individual interfaces or methods. Here is a checklist of the things you have to do in order to extend the peer interfaces described in this chapter to support a target native windowing toolkit.
1. Contact Sun Microsystems with regard to licensing the source code of the Java Development Kit.
2. Identify the graphics primitives used in the target operating system.
3. Implement each of the peer interfaces described in this chapter, using the native methods of the target windowing system. The implementations for the windowing toolkits already supported (Motif, WindowsNT, and Windows95) will help you understand exactly what needs to be done.
4. Extend the java.awt.Toolkit class to create a GUI-dependent class for the target windowing system. This class will include methods to create each of the peer classes implemented in Step 3.
5. Compile and install the classes in the appropriate directories.
The Java language is growing in popularity as the language of choice for cross-platform application development. When porting the Java Development Kit to a new operating system or to a new windowing system, the peer interfaces have to be ported to conform to the application programming interface of the target system. The AWT Peer interfaces clearly separate the platform dependent (physical) abstractions of the windowing toolkit from the user-interface (logical ) abstractions, thus making the job easier for developers who are porting Java.
Table 9-1 summarizes the interfaces described in this chapter. The rest of the chapter presents the detailed descriptions of the methods defined in each of the interfaces.
|
||||||||||||||||||||||||||||||||||||||||||||||||||
ComponentPeer
Purpose
This interface defines the API between the Component class and the underlying operating system GUI primitives used for querying and modifying the properties associated with an AWT component.
Syntax
public interface ComponentPeer extends Object
Description
This interface defines the API between the Component class and the underlying operating system GUI primitives used for querying and modifying graphical components. Native code that uses the API of the underlying GUI toolkit to perform these tasks is encapsulated in a GUI-dependent class that implements this interface. Figure 9-3 shows the inheritance hierarchy for the ComponentPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.ComponentPeer;
Constructors
None.
Parameters
None.
Figure 9-3 Inheritance hierarchy for the ComponentPeer
interface
checkImage(Image, int, int, ImageObserver)
InterfaceName
ComponentPeer
Purpose
Returns the status of construction of the specified image object.
Syntax
public abstract int checkImage(Image img, int w, int h, ImageObserver o)
Parameters
img
The Image object whose screen representation is being constructed.
w
The width of the image to check the status of.
h
The height of the image to check the status of.
o
The ImageObserver object that is to be notified as the specified image is being constructed.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to determine the status of construction of the screen representation of the Image object specified as a parameter to this method.
Imports
import java.awt.peer.ComponentPeer;
Returns
This method returns an integer value that indicates the status of construction of the Image object as indicated by the specified class that implements the ImageObserver interface.
See Also
The checkImage method of the Component class in Chapter 2
createImage(ImageProducer)
InterfaceName
ComponentPeer
Purpose
Creates an Image from the producer object which is an instance of a class that implements the ImageProducer interface.
Syntax
public abstract Image createImage(ImageProducer producer)
Parameters
producer
The ImageProducer object from which the image is created.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to create the image from the ImageProducer object.
Imports
import java.awt.peer.ComponentPeer;
Returns
The return value of this method is an Image object that represents the image that was produced by the ImageProducer.
See Also
The createImage(ImageProducer) method of the Component class in Chapter 2
createImage(int, int)
InterfaceName
ComponentPeer
Purpose
Creates an Image of the specified dimensions. This image can be used for updating the screen using the double-buffering technique.
Syntax
public abstract Image createImage(int width, int height)
Parameters
width
The width of the image to create.
height
The height of the image to create.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to create the off-screen representation of the Image object with the specified width and height.
Imports
import java.awt.peer.ComponentPeer;
Returns
The return value of this method is an Image object that represents the image that can be used for double-buffering.
See Also
The createImage(int, int) method of the Component class in Chapter 2
disable()
InterfaceName
ComponentPeer
Purpose
Disables the Component (associated with this peer) so that it neither responds to user actions nor generates events.
Syntax
public abstract void disable()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to disable the component from responding to events.
Imports
import java.awt.peer.ComponentPeer;
Returns
None.
See Also
The disable method of the Component class in Chapter 2
dispose()
InterfaceName
ComponentPeer
Purpose
Frees the resources allocated to this peer object.
Syntax
public abstract void dispose()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to free all resources that have been allocated to this peer object. The Component object invokes this method to destroy the ComponentPeer object.
Imports
import java.awt.peer.ComponentPeer;
Returns
None.
See Also
The dispose method of the Component class in Chapter 2
enable()
InterfaceName
ComponentPeer
Purpose
Enables the Component object, so that it responds to events.
Syntax
public abstract void enable()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment such that the Component object generates events in response to user actions, etc.
Imports
import java.awt.peer.ComponentPeer;
Returns
None.
See Also
The enable method of the Component class in Chapter 2
getColorModel()
InterfaceName
ComponentPeer
Purpose
Obtains the RGB values for the ColorModel used to display the Component on the current output device.
Syntax
public abstract ColorModel getColorModel()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to determine the Component object's color values in RGB notation.
Imports
import java.awt.peer.ComponentPeer;
Returns
This method returns a ColorModel object that describes the RGB color model used to display the component on the output device.
See Also
The getColorMethod method of the Component class in Chapter 2; the ColorModel class in Chapter 7
getFontMetrics(Font)
InterfaceName
ComponentPeer
Purpose
Obtains information about the properties of the specified font for this Component.
Syntax
public abstract FontMetrics getFontMetrics(Font font)
Parameters
font
The font object whose metrics are to be retrieved.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to determine the various metrics of the font used by the Component object.
Imports
import java.awt.peer.ComponentPeer;
Returns
This method returns a FontMetrics object that describes the characteristics of the font used by the component (associated with this peer).
See Also
The getFontMetrics method of the Component class in Chapter 2; the FontMetrics class in Chapter 7
getGraphics()
InterfaceName
ComponentPeer
Purpose
Obtains information about the graphics context of the Component that created this peer object.
Syntax
public abstract Graphics getGraphics()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to get the graphics context information for the Component.
Imports
import java.awt.peer.ComponentPeer;
Returns
The Graphics object returned by this method describes the graphics context of the component. A value of null is returned if the Component is not currently displayed on the screen.
See Also
The getGraphics method of the Component class described in Chapter 2; the Graphics class described in Chapter 1
getToolkit()
InterfaceName
ComponentPeer
Purpose
Gets an instance of the GUI-dependent toolkit used to bind the AWT classes to a particular graphics environment implementation.
Syntax
public abstract Toolkit getToolkit()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to return a Toolkit object for the underlying graphics environment.
Imports
import java.awt.peer.ComponentPeer;
Returns
The Toolkit object returned by this method is a GUI-specific implementation of the Toolkit class. It is the interface between the AWT graphical components and the graphical components of the native graphical toolkit.
See Also
The getToolkit method of the Component class described in Chapter 2; the Toolkit class described in Chapter 3
handleEvent(Event)
InterfaceName
ComponentPeer
Purpose
The event handler for events that occur in the Component object that are neither handled by the object's event handling method nor its container's event handling method.
Syntax
public abstract boolean handleEvent(Event e)
Parameters
e
The event that was detected.
Description
The peer object's handleEvent method is invoked to handle events that are neither handled by the component's handleEvent method nor by its container's handleEvent method. If a component's event handling method (handleEvent) does not handle an event, the event is passed to the event handling method of the component's container. If this container does not handle the event either, then the event is passed to this method of the component's peer object.
Imports
import java.awt.peer.ComponentPeer;
Returns
This method returns true if it handles the event, and false if it does not handle the event.
See Also
The handleEvent method of the Component class described in Chapter 2; the Event class described in Chapter 3
hide()
InterfaceName
ComponentPeer
Purpose
Hides the Component so that it is not visible on the screen.
Syntax
public abstract void hide()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to hide the component.
Imports
import java.awt.peer.ComponentPeer;
Returns
None.
See Also
The hide method of the Component class described in Chapter 2
minimumSize()
InterfaceName
ComponentPeer
Purpose
Determines the minimum dimensions of the Component object.
Syntax
public abstract Dimension minimumSize()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to determine the minimum dimensions of the Component associated with this peer object.
Imports
import java.awt.peer.ComponentPeer;
Returns
This method returns a Dimension object that contains the minimum width and height measurements required of the Component object.
See Also
The minimumSize method of the Component class described in Chapter 2
nextFocus()
InterfaceName
ComponentPeer
Purpose
Moves the input focus to the next component.
Syntax
public abstract void nextFocus()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to shift the input focus to the next component in the GUI.
Imports
import java.awt.peer.ComponentPeer;
Returns
None.
See Also
The nextFocus method of the Component class described in Chapter 2
paint(Graphics)
InterfaceName
ComponentPeer
Purpose
Paints the Component on the output device using the specified graphics context.
Syntax
public abstract void paint(Graphics g)
Parameters
g
The graphics context object.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment in order to paint the appearance of the Component onto the output device whose characteristics are specified by the graphics context object g.
Imports
import java.awt.peer.ComponentPeer;
Returns
None.
See Also
The paint method of the Component class described in Chapter 2
preferredSize()
InterfaceName
ComponentPeer
Purpose
Determines the ideal dimensions of the Component object.
Syntax
public abstract Dimension preferredSize()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to determine the preferred dimensions of the Component object.
Imports
import java.awt.peer.ComponentPeer;
Returns
This method returns a Dimension object that contains the ideal width and height measurements for the Component object.
See Also
The preferredSize method of the Component class described in Chapter 2
prepareImage(Image, int, int, ImageObserver)
InterfaceName
ComponentPeer
Purpose
Prepares an image (asynchronously) for rendering onto the current output device.
Syntax
public abstract boolean prepareImage(Image img, int w, int h, ImageObserver o)
Parameters
img
The image to prepare for rendering onto this Component.
w
The width of the image to be prepared for rendering.
h
The height of the image to be prepared for rendering.
o
This parameter denotes the ImageObserver object that is notified as the image specified by img is being prepared for rendering.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to prepare an image for rendering by creating a scaled representation of it.
Imports
import java.awt.peer.ComponentPeer;
Returns
This method returns the value of true if the image to be rendered is already prepared and ready for rendering, and false if it is not prepared.
See Also
The prepareImage method of the Component class described in Chapter 2
print(Graphics)
InterfaceName
ComponentPeer
Purpose
Prints the Component on the device whose graphics context is specified.
Syntax
public abstract void print(Graphics g)
Parameters
g
The graphics context object to use for printing this Component.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to print the Component on the specified graphics context. The default implementation of this method is to invoke the paint method.
Imports
import java.awt.peer.ComponentPeer;
Returns
None.
See Also
The print method of the Component class described in Chapter 2
repaint(long, int, int, int, int)
InterfaceName
ComponentPeer
Purpose
Repaints the specified rectangular area of the Component and updates this area as soon as possible.
Syntax
public abstract void repaint(long tm, int x, int y, int width, int height)
Parameters
tm
The maximum amount of time (expressed in milliseconds) before the update method is invoked.
x
The x coordinate of the top-left part of the area of the Component to be repainted.
y
The y coordinate of the top-left part of the area of the Component to be repainted.
width
The width of the area of the Component to be repainted.
height
The height of the area of the Component to be repainted.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to repaint and update the rectangular area defined by the parameters to this method.
Imports
import java.awt.peer.ComponentPeer;
Returns
None.
See Also
The repaint method of the Component class described in Chapter 2
requestFocus()
InterfaceName
ComponentPeer
Purpose
Requests that the Component associated with this peer receive the input focus.
Syntax
public abstract void requestFocus()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment requesting the native toolkit to change the input focus to the Component associated with this peer object.
Imports
import java.awt.peer.ComponentPeer;
Returns
None.
See Also
The requestFocus method of the Component class described in Chapter 2
reshape(int, int, int, int)
InterfaceName
ComponentPeer
Purpose
Changes the shape of the Component such that it fits into the specified rectangular area.
Syntax
public abstract void reshape(int x, int y, int width, int height)
Parameters
x
The x coordinate of the top-left corner of the bounding box.
y
The y coordinate of the top-left corner of the bounding box.
width
The width of the bounding box.
height
The height of the bounding box.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to alter the shape of the Component such that it fits the specified bounding box.
Imports
import java.awt.peer.ComponentPeer;
Returns
None.
See Also
The reshape method of the Component class described in Chapter 2
setBackground(Color)
InterfaceName
ComponentPeer
Purpose
Sets the background color of the Component to the specified color.
Syntax
public abstract void setBackground(Color c)
Parameters
c
The Color value for the background of the Component associated with this peer object.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to change the color used for painting the background of the Component to the specified color.
Imports
import java.awt.peer.ComponentPeer;
Returns
None.
See Also
The setBackground method of the Component class described in Chapter 2
setFont(Font)
InterfaceName
ComponentPeer
Purpose
Changes the font used in the Component to the specified font.
Syntax
public abstract void setFont(Font f)
Parameters
f
The font for the Component associated with this peer object.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to change the font used for writing text in the Component.
Imports
import java.awt.peer.ComponentPeer;
Returns
None.
See Also
The setFont method of the Component class described in Chapter 2
setForeground(Color)
InterfaceName
ComponentPeer
Purpose
Sets the foreground color of the Component to the specified color
Syntax
public abstract void setForeground(Color c)
Parameters
c
The foreground color of the Component associated with this peer object.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to change the color used for painting the foreground of the Component to the specified color.
Imports
import java.awt.peer.ComponentPeer;
Returns
None.
See Also
The setForeground method of the Component class described in Chapter 2
show()
InterfaceName
ComponentPeer
Purpose
Displays the Component.
Syntax
public abstract void show()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to display the Component on the current output device.
Imports
import java.awt.peer.ComponentPeer;
Returns
None.
See Also
The show method of the Component class described in Chapter 2.
ButtonPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a button object.
Syntax
public interface ButtonPeer extends Object extends ComponentPeer
Description
This interface defines the API between the Button class and the underlying operating system GUI primitives used with button objects. Native code that uses the API of the underlying GUI toolkit to create and manage a button object is encapsulated in a GUI-dependent class that implements this interface. Figure 9-4 shows the inheritance hierarchy for the ButtonPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.ButtonPeer;
Constructors
None.
Parameters
None.
Figure 9-4 Inheritance hierarchy for the ButtonPeer interface
setLabel(String)
InterfaceName
ButtonPeer
Purpose
Displays the specified string on the button.
Syntax
public abstract void setLabel(String label)
Parameters
label
The text string for the Button label.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to set the label of the button object to the string specified as the parameter to this method.
Imports
import java.awt.peer.ButtonPeer;
Returns
None.
See Also
The setLabel method of the Button class described in Chapter 4
CanvasPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a Canvas object.
Syntax
public interface CanvasPeer extends Object extends ComponentPeer
Description
This interface defines the API between the Canvas class and the underlying operating system GUI primitives used with general-purpose Canvas objects. Native code that uses the API of the underlying GUI toolkit to create and manage a Canvas object is encapsulated in a GUI-dependent class that implements this interface. The GUI-dependent class that implements the ComponentPeer interface implements all the GUI-dependent functionality that is required of a Canvas object. This GUI-dependent class is the interface between the Canvas class and the underlying GUI toolkit of the platform on which the Java applications are being executed. Figure 9-5 shows the inheritance hierarchy for the CanvasPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.CanvasPeer;
Constructors
None.
Parameters
None.
Figure 9-5 Inheritance hierarchy for the CanvasPeer interface
CheckboxPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a checkbox object.
Syntax
public interface CheckboxPeer extends Object extends ComponentPeer
Description
This interface defines the API between the Checkbox class and the underlying operating system GUI primitives used with Checkbox objects. Native code that uses the API of the underlying GUI toolkit to create and manage a Checkbox object is encapsulated in a GUI-dependent class that implements this interface. Figure 9-6 shows the inheritance hierarchy for the CheckboxPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.CheckboxPeer;
Constructors
None.
Parameters
None.
Figure 9-6 Inheritance hierarchy for the CheckboxPeer
interface
setCheckboxGroup(CheckboxGroup)
InterfaceName
CheckboxPeer
Purpose
Associates the Checkbox object that created this peer object with the CheckboxGroup object specified
Syntax
public abstract void setCheckboxGroup(CheckboxGroup g)
Parameters
g
The CheckboxGroup object to which the Checkbox object associated with this CheckboxPeer object is assigned.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to associate the Checkbox object that created this peer object with the CheckboxGroup object specified as the parameter to this method.
Imports
import java.awt.peer.CheckboxPeer;
Returns
None.
See Also
The setCheckboxGroup method of the Checkbox class; the CheckboxGroup class described in Chapter 6
setLabel(String)
InterfaceName
CheckboxPeer
Purpose
Sets the text label of the Checkbox
Syntax
public abstract void setLabel(String label)
Parameters
label
The text string to display on the label of the Checkbox.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to set the label of the Checkbox object associated with this peer object to the string specified as the parameter to this method.
Imports
import java.awt.peer.CheckboxPeer;
Returns
None.
See Also
The setLabel method of the Checkbox class described in Chapter 6
setState(boolean)
InterfaceName
CheckboxPeer
Purpose
Sets the checkbox state to on or off.
Syntax
public abstract void setState(boolean state)
Parameters
state
A value of true causes the check mark to appear, and a value of false "unchecks" the Checkbox object associated with this CheckboxPeer object.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to set the state of the Checkbox to either on (checked) or off (unchecked), depending on whether the value of state is true or false.
Imports
import java.awt.peer.CheckboxPeer;
Returns
None.
See Also
The setState method of the Checkbox class described in Chapter 6
ChoicePeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a pop-up menu of choices.
Syntax
public interface ChoicePeer extends Object extends ComponentPeer
Description
This interface defines the API between the Choice class and the underlying operating system GUI primitives used for creating and interacting with pop-up menu objects. Native code that uses the API of the underlying GUI toolkit to create and manage a pop-up menu of choices is encapsulated in a GUI-dependent class that implements this interface. Figure 9-7 shows the inheritance hierarchy for the ChoicePeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.ChoicePeer;
Constructors
None.
Parameters
None.
Figure 9-7 Inheritance hierarchy for the ChoicePeer interface
addItem(String, int)
InterfaceName
ChoicePeer
Purpose
Adds a text string to the pop-up menu at the specified position in the list of choices.
Syntax
public abstract void addItem(String item, int index)
Parameters
item
The text to insert into the Choice object associated with this ChoicePeer object.
index
The index at which to insert the specified text in the list of choices.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to add the specified text string to the pop-up menu of choices.
Imports
import java.awt.peer.ChoicePeer;
Returns
None.
See Also
The addItem method of the Choice class described in Chapter 6
select(int)
InterfaceName
ChoicePeer
Purpose
Selects the text string at the index position in the list of choices.
Syntax
public abstract void select(int index)
Parameters
index
The index into the list of choices of the item to select.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to select the specified item in the Choice object associated with this peer object.
Imports
import java.awt.peer.ChoicePeer;
Returns
None.
See Also
The select method of the Choice class described in Chapter 6
LabelPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a label object.
Syntax
public interface LabelPeer extends Object extends ComponentPeer
Description
This interface defines the API between the Label class and the underlying operating system GUI primitives used for creating and interacting with simple label objects that display a noneditable text string. Native code that uses the API of the underlying GUI toolkit to create and manage a label object is encapsulated in a GUI-dependent class that implements this interface. Figure 9-8 shows the inheritance hierarchy for the LabelPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.LabelPeer;
Constructors
None.
Parameters
None.
Figure 9-8 Inheritance hierarchy for the LabelPeer interface
setAlignment(int)
InterfaceName
LabelPeer
Purpose
Sets the alignment of the text string on the label.
Syntax
public abstract void setAlignment(int alignment)
Parameters
alignment
The alignment mode for the text string to be displayed in the Label object for which this LabelPeer object was created.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to align the label object's text string as specified by the alignment parameter.
Imports
import java.awt.peer.LabelPeer;
Returns
None.
See Also
The setAlignment method of the Label class described in Chapter 4
setText(String)
InterfaceName
LabelPeer
Purpose
Changes the text string displayed on the label.
Syntax
public abstract void setText(String label)
Parameters
label
The text for the label.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to display the specified text on the label object.
Imports
import java.awt.peer.LabelPeer;
Returns
None.
See Also
The setText method of the Label class described in Chapter 4
ListPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a list object.
Syntax
public interface ListPeer extends Object extends ComponentPeer
Description
This interface defines the API between the List class and the underlying operating system GUI primitives used for creating and interacting with graphical objects that contain a scrolling list of text strings. Native code that uses the API of the underlying GUI toolkit to create and manage a list object is encapsulated in a GUI-dependent class that implements this interface. Figure 9-9 shows the inheritance hierarchy for the ListPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.ListPeer;
Constructors
None.
Parameters
None.
Figure 9-9 Inheritance hierarchy for the ListPeer interface
addItem(String, int)
InterfaceName
ListPeer
Purpose
Adds a text string at a specified position in the list.
Syntax
public abstract void addItem(String item, int index)
Parameters
item
The text string to add to the list.
index
The index at which to insert the specified text
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to add the specified string at the specified index in the list object for which this peer object was created.
Imports
import java.awt.peer.ListPeer;
Returns
None.
See Also
The addItem method of the List class described in Chapter 5
clear()
InterfaceName
ListPeer
Purpose
Empties the list.
Syntax
public abstract void clear()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to remove all the text strings from the list object.
Imports
import java.awt.peer.ListPeer;
Returns
None.
See Also
The clear method of the List class described in Chapter 5
delItems(int, int)
InterfaceName
ListPeer
Purpose
Removes a specified range of items from the list object.
Syntax
public abstract void delItems(int start, int end)
Parameters
start
The position of the first item to be deleted.
end
The index of the last item to be removed.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to remove all the text strings between the start and end indices in the list.
Imports
import java.awt.peer.ListPeer;
Returns
None.
See Also
The delItems method of the List class described in Chapter 5
deselect(int)
InterfaceName
ListPeer
Purpose
Deselects the item at the specified index in the list.
Syntax
public abstract void deselect(int index)
Parameters
index
The position of the text string to deselect.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to remove the highlight bar from around the item at the position specified by index.
Imports
import java.awt.peer.ListPeer;
Returns
None.
See Also
The deselect method of the List class described in Chapter 5
getSelectedIndexes()
InterfaceName
ListPeer
Purpose
Gets the indices of the selected items in the list.
Syntax
public abstract int[] getSelectedIndexes()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to determine the items in the list that have been selected.
Imports
import java.awt.peer.ListPeer;
Returns
This method returns an array containing integer values that indicate the positions that have been selected in the list.
See Also
The getSelectedIndexes method of the List class described in Chapter 5
makeVisible(int)
InterfaceName
ListPeer
Purpose
Forces the item at the specified index in the list to be made visible.
Syntax
public abstract void makeVisible(int index)
Parameters
index
The index of the item in the list that is forced to be made visible.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to bring the specified text item into the visible area of the list box, scrolling the items in the list object if necessary.
Imports
import java.awt.peer.ListPeer;
Returns
None.
See Also
The makeVisible method of the List class described in Chapter 5
minimumSize()
InterfaceName
ListPeer
Purpose
Determines the minimum height and width for a List object containing the specified number of rows.
Syntax
public abstract Dimension minimumSize(int v)
Parameters
v
The number of rows in the list.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to determine the minimum dimension required if the List object associated with this peer object has v number of rows.
Imports
import java.awt.peer.ListPeer;
Returns
This method returns a Dimension object that contains the minimum width and height measurements required of the List object.
See Also
The minimumSize method of the List class described in Chapter 5
preferredSize(int)
InterfaceName
ListPeer
Purpose
Determines the ideal dimensions for a List object containing the specified number of rows.
Syntax
public abstract Dimension preferredSize(int v)
Parameters
v
The number of rows in the list.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to determine the ideal dimension required if the List object associated with this peer object has v number of rows.
Imports
import java.awt.peer.ListPeer;
Returns
This method returns a Dimension object that contains the ideal width and height measurements required of the List object.
See Also
The preferredSize method of the List class described in Chapter 5
select(int)
InterfaceName
ListPeer
Purpose
Selects the text item at the specified position in the list.
Syntax
public abstract void select(int index)
Parameters
index
The index of the item in the list to be selected.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to highlight the item at the position specified by index.
Imports
import java.awt.peer.ListPeer;
Returns
None.
See Also
The select method of the List class described in Chapter 5
setMultipleSelections(boolean)
InterfaceName
ListPeer
Purpose
Enables and disables multiple selection of items in the list.
Syntax
public abstract void setMultipleSelections(boolean mFlag)
Parameters
mFlag
If the value of mFlag is
true, then multiple items in the list can be selected.
If the value of mFlag is false, then the list functions as a
single-selection list in which only one of the items displayed can be selected.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI, to set whether or not the user can select multiple items in the List component associated with this peer object.
Imports
import java.awt.peer.ListPeer;
Returns
None.
See Also
The setMultipleSelections method of the List class described in Chapter 5
ScrollbarPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a scrollbar object.
Syntax
public interface ScrollbarPeer extends Object extends ComponentPeer
Description
This interface defines the API between the Scrollbar class and the underlying operating system GUI primitives used for creating and interacting with scrollbar objects. Native code that uses the API of the underlying GUI toolkit to create and manage a scrollbar object is encapsulated in a GUI-dependent class that implements this interface. Figure 9-10 shows the inheritance hierarchy for the ScrollbarPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.ScrollbarPeer;
Constructors
None.
Parameters
None.
Figure 9-10 Inheritance hierarchy for the ScrollbarPeer
interface
setLineIncrement(int)
InterfaceName
ScrollbarPeer
Purpose
Sets the step size for decrements and increments when the line up or line down arrow buttons of the scrollbar are invoked.
Syntax
public abstract void setLineIncrement(int l)
Parameters
l
The line increment size.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to set the step size for line increments and decrements of the Scrollbar object associated with this peer object.
Imports
import java.awt.peer.ScrollbarPeer;
Returns
None.
See Also
The setLineIncrement method of the Scrollbar class described in Chapter 4
setPageIncrement(int)
InterfaceName
ScrollbarPeer
Purpose
Sets the step size for decrements or increments when the page up or page down arrow buttons of the scrollbar are invoked.
Syntax
public abstract void setPageIncrement(int l)
Parameters
l
The page increment size.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to set the step size for page increments and decrements of the Scrollbar object associated with this peer object.
Imports
import java.awt.peer.ScrollbarPeer;
Returns
None.
See Also
The setPageIncrement method of the Scrollbar class described in Chapter 4
setValue(int)
InterfaceName
ScrollbarPeer
Purpose
Sets the value of the current position of the Scrollbar to the specified value.
Syntax
public abstract void setValue(int p)
Parameters
p
The new value for the current position of the Scrollbar.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to set the value of the current position of the Scrollbar object associated with this peer object.
Imports
import java.awt.peer.ScrollbarPeer;
Returns
None.
See Also
The setValue method of the Scrollbar class described in Chapter 4
setValues(int, int, int, int)
InterfaceName
ScrollbarPeer
Purpose
Sets various parameters associated with the ScrollBar object.
Syntax
public abstract void setValues(int value, int visible, int minScroll, int maxScroll)
Parameters
value
The position of the scrollbar thumb in the current window.
visible
The size of the visible region of the area that is being scrolled using the scrollbar.
minScroll
The minimum value of the scrollbar.
maxScroll
The maximum value of the scrollbar.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to set the specified parameters for the Scrollbar object associated with this peer object.
Imports
import java.awt.peer.ScrollbarPeer;
Returns
None
See Also
The setValues method of the Scrollbar class described in Chapter 4
ContainerPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a container object.
Syntax
public interface ContainerPeer extends Object extends ComponentPeer
Description
This interface defines the API between the Container class and the underlying operating system GUI primitives used for creating and interacting with graphical components that can contain other graphical components. Native code that uses the API of the underlying GUI toolkit to create and manage a GUI component that can contain other graphical components is encapsulated in a GUI-dependent class that implements this interface. Figure 9-11 shows the inheritance hierarchy for the ContainerPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.ContainerPeer;
Constructors
None.
Parameters
None.
Figure 9-11 Inheritance hierarchy for the ContainerPeer
interface
insets()
InterfaceName
ContainerPeer
Purpose
Determines the top, left, bottom, right insets for the Container object.
Syntax
public abstract Insets insets()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to determine the extra space that must be added as padding on the top, left, bottom, and right sides of the Container object.
Imports
import java.awt.peer.ContainerPeer;
Returns
This method returns an Insets object that specifies the top, left, bottom, and right padding that must be subtracted from the dimensions of the Container object in order to determine the area required for laying out Components within the Container.
See Also
The insets method of the Container class described in Chapter 3
PanelPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a panel object.
Syntax
public interface PanelPeer extends Object extends ContainerPeer
Description
This interface defines the API between the Panel class and the underlying operating system GUI primitives used for creating and interacting with panel graphical components. Native code that uses the API of the underlying GUI toolkit to create and manage a panel object is encapsulated in a GUI-dependent class that implements this interface. This GUI-dependent class is the interface between the Panel class and the underlying GUI toolkit of the platform on which the Java applications are being executed. Figure 9-12 shows the inheritance hierarchy for the PanelPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.PanelPeer;
Constructors
None.
Parameters
None.
Figure 9-12 Inheritance hierarchy for the PanelPeer interface
WindowPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a top-level window object.
Syntax
public interface WindowPeer extends Object extends ContainerPeer
Description
This interface defines the API between the Window class and the underlying operating system GUI primitives used for creating and interacting with top-level windows. These windows have neither a title bar nor a border. Native code that uses the API of the underlying GUI toolkit to create and manage a top-level container object, is encapsulated in a GUI-dependent class that implements this interface. Figure 9-13 shows the inheritance hierarchy for the WindowPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.WindowPeer;
Constructors
None.
Parameters
None.
Figure 9-13 Inheritance hierarchy for the WindowPeer
interface
toBack()
InterfaceName
WindowPeer
Purpose
Sends the parent frame object to the back of the Window object associated with this peer.
Syntax
public abstract void toBack()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to push the parent Frame window object to the back of the Window.
Imports
import java.awt.peer.WindowPeer;
Returns
None.
See Also
The toBack method of the Window class described in Chapter 3
toFront()
InterfaceName
WindowPeer
Purpose
Brings the parent frame object to the front of the Window object associated with this peer.
Syntax
public abstract void toFront()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to bring the parent Frame window object to the front of the Window object.
Imports
import java.awt.peer.WindowPeer;
Returns
None.
See Also
The toFront method of the Window class described in Chapter 3
DialogPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a Dialog box object.
Syntax
public interface DialogPeer extends Object extends WindowPeer
Description
This interface defines the API between the Dialog class and the underlying operating system GUI primitives used for creating and interacting with dialog box object. The GUI-dependent class that creates a dialog box object must implement this interface. The methods defined in this interface are implemented in native code, using the API of the underlying GUI toolkit to create and manage a dialog box object. Figure 9-14 shows the inheritance hierarchy for the DialogPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.DialogPeer;
Constructors
None.
Parameters
None.
Figure 9-14 Inheritance hierarchy for the DialogPeer
interface
setResizable(boolean)
InterfaceName
DialogPeer
Purpose
Sets whether the dialog box can be resized or not.
Syntax
public abstract void setResizable(boolean resizable)
Parameters
resizable
A value of true makes the Dialog component resizable; false means the Dialog window is not resizable.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to enable and disable the resizable property of the Dialog window object associated with this peer.
Imports
import java.awt.peer.DialogPeer;
Returns
None.
See Also
The setResizable method of the Dialog class described in Chapter 5
setTitle(String)
InterfaceName
DialogPeer
Purpose
Sets the text string on the title bar of the Dialog window.
Syntax
public abstract void setTitle(String title)
Parameters
title
The text to display in the title bar of the Dialog window.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to set the title of the Dialog window to the string specified in the parameter to this method.
Imports
import java.awt.peer.DialogPeer;
Returns
None.
See Also
The setTitle method of the Dialog class described in Chapter 5
FileDialogPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a FileDialog window that displays a list of files and allows the user to select a file.
Syntax
public interface FileDialogPeer extends Object extends DialogPeer
Description
This interface defines the API between the FileDialog class and the underlying operating system GUI primitives used for creating and interacting with dialog box windows that display a list of files and allow the user to select from the list. The GUI-dependent class that creates a file dialog box window must implement this interface. The methods defined in this interface are implemented in native code using the API of the underlying GUI toolkit to create and manage a dialog box window that allows the user to pick a file from a list of filenames. Figure 9-15 shows the inheritance hierarchy for the FileDialogPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.FileDialogPeer;
Constructors
None.
Parameters
None.
Figure 9-15 Inheritance hierarchy for the FileDialogPeer
interface
setDirectory(String)
InterfaceName
FileDialogPeer
Purpose
Sets the directory from which the user is prompted to select a file.
Syntax
public abstract void setDirectory(String dir)
Parameters
dir
The name of the directory from which the user is prompted to select a file.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to display the text string specified in dir in a window on the FileDialog box.
Imports
import java.awt.peer.FileDialogPeer;
Returns
None.
See Also
The setDirectory method of the FileDialog class described in Chapter 5
setFile(String)
InterfaceName
FileDialogPeer
Purpose
Sets the directory from which the user is prompted to select a file.
Syntax
public abstract void setFile(String file)
Parameters
file
The name of the (default) file for the FileDialog object associated with this peer object.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to display the text string specified in file as a label on the FileDialog box.
Imports
import java.awt.peer.FileDialogPeer;
Returns
None.
See Also
The setFile method of the FileDialog class described in Chapter 5
setFilenameFilter(FilenameFilter)
InterfaceName
FileDialogPeer
Purpose
Sets the filter that determines which files to display for users to select from in the FileDialog box.
Syntax
public abstract void setFilenameFilter(FilenameFilter filter)
Parameters
filter
The file name filter for displaying files in the FileDialog window.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to display the text string specified in filter on a label on the FileDialog box and to perform the appropriate filtering of file names.
Imports
import java.awt.peer.FileDialogPeer;
Returns
None.
See Also
The setFilenameFilter method of the FileDialog class described in Chapter 5
FramePeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a Frame window.
Syntax
public interface FramePeer extends Object extends WindowPeer
Description
This interface defines the API between the Frame class and the underlying operating system GUI primitives used for creating and interacting with top-level frame windows that have a title bar and borders and can optionally have a menu bar. Native code that uses the API of the underlying GUI toolkit to create and manage a top-level frame window object is encapsulated in a GUI-dependent class that implements this interface. Figure 9-16 shows the inheritance hierarchy for the FramePeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.FramePeer;
Constructors
None.
Parameters
None.
Figure 9-16 Inheritance hierarchy for the FramePeer interface
setCursor(int)
InterfaceName
FramePeer
Purpose
Sets the cursor to display when the pointer is within the Frame window associated with this peer object.
Syntax
public abstract void setCursor(int cursorType)
Parameters
cursorType
An integer constant that indicates the type of cursor to display within the Frame window for which this FramePeer was created.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to display the appropriate bitmap image when the pointer is within the bounds of the Frame window associated with this peer.
Imports
import java.awt.peer.FramePeer;
Returns
None.
See Also
The setCursor method of the Frame class described in Chapter 4
setIconImage(Image)
InterfaceName
FramePeer
Purpose
Sets the image of the icon of the Frame window associated with this peer object.
Syntax
public abstract void setIconImage(Image img)
Parameters
img
The image to be used for the icon.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to display the appropriate image when the Frame window is iconized.
Imports
import java.awt.peer.FramePeer;
Returns
None.
See Also
The setIconImage method of the Frame class described in Chapter 4
setMenuBar(MenuBar)
InterfaceName
FramePeer
Purpose
Sets the menu bar for the Frame to the specified MenuBar object.
Syntax
public abstract void setMenuBar(MenuBar mbar)
Parameters
mbar
The MenuBar object that represents the menu bar for the Frame window.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to associate the specified menu bar with the Frame window associated with this peer object.
Imports
import java.awt.peer.FramePeer;
Returns
None.
See Also
The setMenuBar method of the Frame class described in Chapter 4
setResizable(boolean)
InterfaceName
FramePeer
Purpose
Sets whether or not the Frame window can be resized.
Syntax
public abstract void setResizable(boolean resizable)
Parameters
resizable
A boolean value that represents whether or not the Frame window is resizable. If this value is set to true, the Frame window is resizable; if it is set to false, the Frame window is not resizable.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to enable and disable the resizable property of the Frame window associated with this peer.
Imports
import java.awt.peer.FramePeer;
Returns
None.
See Also
The setResizable method of the Frame class described in Chapter 4
setTitle(String)
InterfaceName
FramePeer
Purpose
Sets the text string on the title bar of the frame.
Syntax
public abstract void setTitle(String title)
Parameters
title
The text string to display in the title bar of the Frame window.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to set the title of the Frame window to the string specified in the parameter to this method.
Imports
import java.awt.peer.FramePeer;
Returns
None.
See Also
The setTitle method of the Frame class described in Chapter 4
MenuComponentPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a MenuComponent object.
Syntax
public interface MenuComponentPeer extends Object
Description
This interface defines the API between the MenuComponent class and the underlying operating system GUI primitives used for creating and interacting with graphical objects associated with menus. Native code that uses the API of the underlying GUI toolkit to create and manage a menu component object is encapsulated in a GUI-dependent class that implements this interface. Figure 9-17 shows the inheritance hierarchy for the MenuComponentPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.MenuComponentPeer;
Constructors
None.
Parameters
None.
Figure 9-17 Inheritance hierarchy for the MenuComponentPeer
interface
dispose()
InterfaceName
MenuComponentPeer
Purpose
Frees the resources allocated to the MenuComponent.
Syntax
public abstract void dispose()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to free the resources allocated to the MenuComponent object associated with this peer.
Imports
import java.awt.peer.MenuComponentPeer;
Returns
None.
See Also
The removeNotify method of the MenuComponent class described in Chapter 6
MenuBarPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a MenuBar object.
Syntax
public interface MenuBarPeer extends MenuComponentPeer
Description
This interface defines the API between the MenuBar class and the underlying operating system GUI primitives used for creating and interacting with menu bar objects. Native code that uses the API of the underlying GUI toolkit to create and manage a menu bar object is encapsulated in a GUI-dependent class that implements this interface. Figure 9-18 shows the inheritance hierarchy for the MenuBarPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.MenuBarPeer;
Constructors
None.
Parameters
None.
Figure 9-18 Inheritance hierarchy for the MenuBarPeer
interface
addHelpMenu(Menu)
InterfaceName
MenuBarPeer
Purpose
Adds the specified menu as the help menu for the menu bar.
Syntax
public abstract void addHelpMenu(Menu m)
Parameters
m
The help menu on the menu bar is set to this menu object.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to add the specified menu to the menu bar and to designate it as the help menu.
Imports
import java.awt.peer.MenuBarPeer;
Returns
None.
See Also
The setHelpMenu method of the MenuBar class described in Chapter 6
addMenu(Menu)
InterfaceName
MenuBarPeer
Purpose
Adds a menu to the MenuBar object associated with this peer object.
Syntax
public abstract void addMenu(Menu m)
Parameters
m
The menu object to be added to the menu bar.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to add the specified menu to the menu bar.
Imports
import java.awt.peer.MenuBarPeer;
Returns
None.
See Also
The add method of the MenuBar class described in Chapter 6
delMenu(int)
InterfaceName
MenuBarPeer
Purpose
Removes the specified menu from the menu bar.
Syntax
public abstract void delMenu(int index)
Parameters
index
The index of the menu to remove from the menu bar object associated with this peer.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to remove the specified menu from the menu bar.
Imports
import java.awt.peer.MenuBarPeer;
Returns
None.
See Also
The remove method of the MenuBar class described in Chapter 6
MenuItemPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a MenuItem object.
Syntax
public interface MenuItemPeer extends MenuComponentPeer
Description
This interface defines the API between the MenuItem class and the underlying operating system GUI primitives used for creating and interacting with menu item objects. Native code that uses the API of the underlying GUI toolkit to create and manage a menu item object is encapsulated in a GUI-dependent class that implements this interface. Figure 9-19 shows the inheritance hierarchy for the MenuItemPeer interface.
PackageName
import java.awt.peer
Imports
import java.awt.peer.MenuBarPeer;
Constructors
None.
Parameters
None.
Figure 9-19 Inheritance hierarchy for the MenuItemPeer
interface
disable()
InterfaceName
MenuItemPeer
Purpose
Makes the MenuItem associated with this peer unselectable by the user.
Syntax
public abstract void disable()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to make the menu item unselectable by the user.
Imports
import java.awt.peer.MenuItemPeer;
Returns
None.
See Also
The disable method of the MenuItem class described in Chapter 6
enable()
InterfaceName
MenuItemPeer
Purpose
Makes the MenuItem associated with this peer selectable by the user.
Syntax
public abstract void enable()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to make the menu item selectable by the user.
Imports
import java.awt.peer.MenuItemPeer;
Returns
None.
See Also
The enable method of the MenuItem class described in Chapter 6
setLabel(String)
InterfaceName
MenuItemPeer
Purpose
Sets the text label of the MenuItem to the specified string.
Syntax
public abstract void setLabel(String label)
Parameters
label
The text for the label of the MenuItem for which this peer was created.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to set the text of the menu item to the string specified in label.
Imports
import java.awt.peer.MenuItemPeer;
Returns
None.
See Also
The setLabel method of the MenuItem class described in Chapter 6
CheckboxMenuItemPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a CheckboxMenuItem object.
Syntax
public interface CheckboxMenuItemPeer extends Object extends MenuItemPeer
Description
This interface defines the API between the CheckboxMenuItem class and the underlying operating system GUI primitives used for creating and interacting with checkboxes that can be used as menu item objects. Native code that uses the API of the underlying GUI toolkit to create and manage a checkbox object that can be used in menus is encapsulated in a GUI-dependent class that implements this interface. Figure 9-20 shows the inheritance hierarchy for the CheckboxMenuItemPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.CheckboxMenuItemPeer;
Constructors
None.
Parameters
None.
Figure 9-20 Inheritance hierarchy for the
CheckboxMenuItemPeer interface
setState(boolean)
InterfaceName
CheckboxMenuItemPeer
Purpose
Sets the checkbox state (in the menu) to either on or off.
Syntax
public abstract void setState(boolean t)
Parameters
t
The checkbox is "unchecked" if this value is false. The checkbox is "checked" if the value of this variable is true.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific graphical environment to set the state of the Checkbox to either on (checked) or off (unchecked), depending on whether the value of t is true or false.
Imports
import java.awt.peer.CheckboxMenuItemPeer;
Returns
None.
See Also
The setState method of the CheckboxMenuItem class described in Chapter 6
MenuPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a Menu object.
Syntax
public interface MenuPeer extends MenuItemPeer
Description
This interface defines the API between the Menu class and the underlying GUI primitives that can be components of a menu bar. Native code that uses the API of the underlying GUI toolkit to create and manage a menu object is encapsulated in a GUI-dependent class that implements this interface. Figure 9-21 shows the inheritance hierarchy for the MenuPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.MenuPeer;
Constructors
None.
Parameters
None.
Figure 9-21 Inheritance hierarchy for the MenuPeer interface
addItem(MenuItem)
InterfaceName
MenuPeer
Purpose
Adds the specified MenuItem to the Menu object associated with this peer.
Syntax
public abstract void addItem(MenuItem mItem)
Parameters
mItem
The MenuItem to be added to the menu.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to add the specified menu item to the Menu associated with this peer.
Imports
import java.awt.peer.MenuPeer;
Returns
None.
See Also
The add method of the Menu class described in Chapter 6
addSeparator()
InterfaceName
MenuPeer
Purpose
Adds a separator line in the Menu.
Syntax
public abstract void addSeparator()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to draw a line just below the previous item that was added to the Menu object assoicated with this peer object.
Imports
import java.awt.peer.MenuPeer;
Returns
None.
See Also
The addSeparator method of the Menu class described in Chapter 6
delItem(int)
InterfaceName
MenuPeer
Purpose
Removes the menu item at the index specified by index from the Menu object associated with this peer.
Syntax
public abstract void delItem(int index)
Parameters
index
The index of the item to remove from the Menu object associated with this peer.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to remove the MenuItem at the specified index from the Menu object.
Imports
import java.awt.peer.MenuPeer;
Returns
None.
See Also
The remove method of the Menu class described in Chapter 6
TextComponentPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a TextComponent object.
Syntax
public interface TextComponentPeer extends Object extends ComponentPeer
Description
This interface defines the API between the TextComponent class and the underlying operating system GUI primitives used for creating graphical components in which text can be edited. Native code that uses the API of the underlying GUI toolkit to create and manage a TextComponent object is encapsulated in a GUI-dependent class that implements this interface. Figure 9-22 shows the inheritance hierarchy for the TextComponentPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.TextComponentPeer;
Constructors
None.
Parameters
None.
Figure 9-22 Inheritance hierarchy for the TextComponentPeer
interface
getSelectionEnd()
InterfaceName
TextComponentPeer
Purpose
Returns the position of the end of the text that the user selected.
Syntax
public abstract int getSelectionEnd()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to determine the position of the end of the text selected by the user.
Imports
import java.awt.peer.TextComponentPeer;
Returns
This method returns an integer value that indicates the character position of the last character in the text selected by the user.
See Also
The getSelectionEnd method of the TextComponent class described in Chapter 5
getSelectionStart()
InterfaceName
TextComponentPeer
Purpose
Returns the position of the start of the text that the user selected.
Syntax
public abstract int getSelectionStart()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to determine the position of the beginning of the text selected by the user.
Imports
import java.awt.peer.TextComponentPeer;
Returns
This method returns an integer value that indicates the character position of the first character in the text selected by the user.
See Also
The getSelectionStart method of the TextComponent class described in Chapter 5
getText()
InterfaceName
TextComponentPeer
Purpose
Returns the text that the TextComponent contains.
Syntax
public abstract String getText()
Parameters
None.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to determine the text contained in the TextComponent object associated with this peer.
Imports
import java.awt.peer.TextComponentPeer;
Returns
This method returns a string containing all the text contained in the TextComponent.
See Also
The getText method of the TextComponent class described in Chapter 5
select(int, int)
InterfaceName
TextComponentPeer
Purpose
Selects a range of text.
Syntax
public abstract void select(int selStart, int selEnd)
Parameters
selStart
The position at which to start selecting the text.
selEnd
The position at which to stop selecting the text, starting from selStart.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to select the range of text between the start index selStart and the end index selEnd. Highlighting the selected text is a standard convention followed in most graphical environments.
Imports
import java.awt.peer.TextComponentPeer;
Returns
None.
See Also
The select method of the TextComponent class described in Chapter 5
setEditable(boolean)
InterfaceName
TextComponentPeer
Purpose
Sets whether or not the TextComponent permits editing of the text contained in it.
Syntax
public abstract void setEditable(boolean editable)
Parameters
editable
A value of true makes the text in the TextComponent editable by the user. A value of false means the text in the TextComponent cannot be edited.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to set whether or not the text contained in the TextComponent can be edited.
Imports
import java.awt.peer.TextComponentPeer;
Returns
None.
See Also
The setEditable method of the TextComponent class described in Chapter 5
setText(String)
InterfaceName
TextComponentPeer
Purpose
Sets the string to display in the TextComponent object associated with this peer.
Syntax
public abstract void setText(String s)
Parameters
s
The text to display in the TextComponent object associated with this peer object.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to display the text string s in the TextComponent.
Imports
import java.awt.peer.TextComponentPeer;
Returns
None.
See Also
The setText method of the TextComponent class described in Chapter 5
TextAreaPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a TextArea object.
Syntax
public interface TextAreaPeer extends Object extends TextComponentPeer
Description
This interface defines the API between the TextArea class and the underlying operating system GUI primitives used for displaying, editing, and managing multiline text areas. Native code that uses the API of the underlying GUI toolkit to create and manage a TextArea object is encapsulated in a GUI-dependent class that implements this interface. Figure 9-23 shows the inheritance hierarchy for the TextAreaPeer interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.TextAreaPeer;
Constructors
None.
Parameters
None.
Figure 9-23 Inheritance hierarchy for the TextAreaPeer
interface
insertText(String, int)
InterfaceName
TextAreaPeer
Purpose
Inserts a string of text at a specified index into the existing text in the TextArea object.
Syntax
public abstract void insertText(String txt, int pos)
Parameters
txt
The text to insert into the TextArea object.
pos
The position at which to insert the specified text.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to insert the text string(txt) at the index specified by pos into the TextArea component associated with this peer object.
Imports
import java.awt.peer.TextAreaPeer;
Returns
None.
See Also
The insertText method of the TextArea class described in Chapter 5
minimumSize(int, int)
InterfaceName
TextAreaPeer
Purpose
Determines the minimum height and width for a TextArea object containing the specified number of rows and columns of text.
Syntax
public abstract Dimension minimumSize(int rows, int cols)
Parameters
rows
The number of rows in the TextArea object.
cols
The number of columns in the TextArea object.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to determine the minimum dimension required if the TextArea object associated with this peer object has the specified number of rows and columns of text.
Imports
import java.awt.peer.TextAreaPeer;
Returns
This method returns a Dimension object that contains the minimum width and height measurements required of the TextArea object.
See Also
The minimumSize method of the TextArea class described in Chapter 5
preferredSize(int, int)
InterfaceName
TextAreaPeer
Purpose
Determines the ideal height and width for a TextArea object containing the specified number of rows and columns of text.
Syntax
public abstract Dimension preferredSize(int rows, int cols)
Parameters
rows
The preferred number of rows for the TextArea object.
cols
The preferred number of columns for the TextArea object.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to determine the ideal dimension required if the TextArea object associated with this peer object has the specified number of rows and columns of text.
Imports
import java.awt.peer.TextAreaPeer;
Returns
This method returns a Dimension object that contains the ideal width and height measurements required of the TextArea object.
See Also
The preferredSize method of the TextArea class described in Chapter 5
replaceText(String, int, int)
InterfaceName
TextAreaPeer
Purpose
Replaces a specified range of text with another string of text.
Syntax
public abstract void replaceText (String txt, int start, int end)
Parameters
txt
The new text string to use as the replacement text.
start
The starting position of the text in the TextArea to be replaced.
end
The ending position of the text in the TextArea to be replaced.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to replace the characters between the indices specified by start and end, with the text string supplied in txt.
Imports
import java.awt.peer.TextAreaPeer;
Returns
None.
See Also
The replaceText method of the TextArea class described in Chapter 5
TextFieldPeer
Purpose
Defines the interface that must be implemented by a GUI-dependent class to create and manage a TextField object.
Syntax
public interface TextFieldPeer extends Object extends TextComponentPeer
Description
This interface defines the API between the TextField class and the underlying operating system GUI primitives used for creating graphical components that allow editing of a single line of text. Native code that uses the API of the underlying GUI toolkit to create and manage a TextField object is encapsulated in a GUI-dependent class that implements this interface.
PackageName
java.awt.peer
Imports
import java.awt.peer.TextFieldPeer;
Constructors
None.
Parameters
None.
minimumSize(int)
InterfaceName
TextFieldPeer
Purpose
Determines the minimum height and width for a TextField object containing the specified number of columns.
Syntax
public abstract Dimension minimumSize(int cols)
Parameters
cols
The minimum number of columns the TextField object must have.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to determine the minimum dimension required if the TextField object associated with this peer object has cols number of columns of text.
Imports
import java.awt.peer.TextFieldPeer;
Returns
This method returns a Dimension object that contains the minimum width and height measurements required of the TextField object.
See Also
The minimumSize method of the TextField class described in Chapter 5
preferredSize(int)
InterfaceName
TextFieldPeer
Purpose
Determines the ideal height and width for a TextField object containing the specified number of columns of text.
Syntax
public abstract Dimension preferredSize(int cols)
Parameters
cols
The preferred number of columns the TextField object must have.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to determine the ideal dimension of the TextField object associated with this peer object if it has cols number of columns.
Imports
import java.awt.peer.TextFieldPeer;
Returns
This method returns a Dimension object that contains the ideal width and height measurements required of the TextField object.
See Also
The preferredSize method of the TextField class described in Chapter 5
setEchoCharacter(char)
InterfaceName
TextFieldPeer
Purpose
Sets the character that is echoed when the user enters text in the TextField object associated with this peer.
Syntax
public abstract void setEchoCharacter(char c)
Parameters
c
The character that should be printed in the TextField when the user enters text in the TextField object.
Description
The GUI-dependent class that implements this method must make native calls to the API of the platform-specific GUI to set the echo character for the TextField object to the specified character.
Imports
import java.awt.peer.TextFieldPeer;
Returns
None.
See Also
The setEchoCharacter method of the TextField class described in Chapter 5
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 886
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved