by Debasis Samanta
The java.awt.peer Package includes interfaces used to connect AWT components to their platform specific implementations such as Motif widgets or Microsoft Windows controls. The interfaces in the java.awt.peer are need to be used only if one wants to create a syste specific implementation. This package contains the interfaces as listed below :
Interfaces: Interface ButtonPeer Interface CanvasPeer Interface CheckboxMenuItemPeer Interface CheckboxPeer Interface ChoicePeer Interface ComponentPeer Interface ContainerPeer Interface DialogPeer Interface FileDialogPeer Interface FramePeer Interface LabelPeer Interface ListPeer Interface MenuBarPeer Interface MenuComponentPeer Interface MenuItemPeer Interface MenuPeer Interface PanelPeer Interface ScrollbarPeer Interface TextAreaPeer Interface TextComponentPeer Interface TextFieldPeer Interface WindowPeer
The button peer interface specifies the methods that all implementations of Abstract Window Toolkit buttons must define.
public interface java.awt.peer.ButtonPeer extends java.awt.peer.ComponentPeer { // Methods public abstract void setLabel(String label); // Changes the button's label to be the String argument. }
The canvas peer interface specifies the methods that all implementations of Abstract Window Toolkit canvases must define. In general, canvas implementations only need to implement methods required of all component peers.
public interface java.awt.peer.CanvasPeer extends java.awt.peer.ComponentPeer { }
The check box menu peer interface specifies the methods that all implementations of Abstract Window Toolkit check box menus must define
public interface java.awt.peer.CheckboxMenuItemPeer extends java.awt.peer.MenuItemPeer { // Methods public abstract void setState(boolean t); // Sets the check box to the specifed boolean state: true indicates "on"; false indicates "off." }
The check box peer interface specifies the methods that all implementations of Abstract Window Toolkit check boxes must define
public interface java.awt.peer.CheckboxPeer extends java.awt.peer.ComponentPeer { // Methods public abstract void setCheckboxGroup(CheckboxGroup g); // Sets the group of the checkbox to be the specified CheckboxGroup public abstract void setLabel(String label); // Changes the check box's label to be the string argument. public abstract void setState(boolean state); // Sets the check box to the specifed boolean state: true indicates "on"; false indicates "off" }
The choice menu peer interface specifies the methods that all implementations of Abstract Window Toolkit choice menus must define.
public interface java.awt.peer.ChoicePeer extends java.awt.peer.ComponentPeer { // Methods public abstract void addItem(String item, int index); // Adds an item to the choice menu at the specified position. public abstract void select(int index); // Sets the selected item to be the item at the specified position. }
The component peer interface specifies the methods that all implementations of Abstract Window Toolkit components must define.
public interface java.awt.peer.ComponentPeer { // Methods public abstract int checkImage(Image img, int w, int h, ImageObserver o); public abstract Image createImage(ImageProducer p); public abstract Image createImage(int w , int h ); public abstract void disable(); public abstract void dispose(); public abstract void enable(); public abstract ColorModel getColorModel(); public abstract FontMetrics getFontMetrics(Font font); public abstract Graphics getGraphics(); public abstract Toolkit getToolkit(); public abstract boolean handleEvent(Event e); public abstract void hide(); public abstract Dimension minimumSize(); public abstract void nextFocus(); public abstract void paint(Graphics g); public abstract Dimension preferredSize(); public abstract boolean prepareImage(Image img, int w, int h,ImageObserver o); public abstract void print(Graphics g); public abstract void repaint(long tm, int x, int y, int width,int height); public abstract void requestFocus(); public abstract void reshape(int x, int y, int width, int height); public abstract void setBackground(Color c); public abstract void setFont(Font f); public abstract void setForeground(Color c); public abstract void show(); } Methods are stated in Table 6.1.
Table 6.1
Table 6.1 (Contd..)
handleEvent(Event e) |
This method is called when any event occurs inside the component. The method returns true to indicate that it has successfully handled the action; or false if the event that triggered the action should be passed up to the component's containing object. |
hide() |
Hides the component. |
minimumSize() |
Returns : the minimum size of this component. |
nextFocus() |
Moves the focus to the next component |
paint(Graphics g) |
Paints
the component.The coordinator of the graphics context is the
top-left corner of the components. The clipping region of the
graphics context is the rectangle of the component. |
preferredSize() |
Returns : the preferred size of this component. |
prepareImage(....) |
Prepares an image for rendering on this component at the specified width and height. The image data is downloaded asynchronously in another thread and an appropriately scaled screen representation of the image is generated. |
print(Graphics g) |
Prints this component. |
repaint(....) |
Repaints the specified rectangle of the component. |
requestFocus() |
Requests the input focus. |
reshape( ...) |
Reshapes the component to the specified bounding rectangle. |
setBackground(Color c) |
Sets the background color for the component. |
setFont(Font f) |
Sets the font of the component. |
setForeground(Color c) |
Sets the foreground color for the component. |
show() |
Shows the component: if the component had been made invisible by a call to the hide method, make the component visible again. |
The container peer interface specifies the methods that all implementations of Abstract Window Toolkit containers must define.
public interface java.awt.peer.ContainerPeer extends java.awt.peer.ComponentPeer { // Methods public abstract Insets insets(); /* Determines the insets of the container, which indicate the size of the border of the container. A Frame, for example, has a top inset that corresponds to the height of the frame's title bar. */ }
The dialog window peer interface specifies the methods that all implementations of Abstract Window Toolkit dialog windows must define.
public interface java.awt.peer.DialogPeer extends java.awt.peer.WindowPeer { // Methods public abstract void setResizable(boolean resizeable); // Sets the resizable flag. public abstract void setTitle(String title); // Sets the title of the dialog window. }
The dialog window peer interface specifies the methods that all implementations of Abstract Window Toolkit dialog windows must define.
public interface java.awt.peer.DialogPeer extends java.awt.peer.WindowPeer { // Methods public abstract void setResizable(boolean resizeable); // Sets the resizable flag. public abstract void setTitle(String title); // Sets the title of the dialog window. }
The file dialog window peer interface specifies the methods that all implementations of Abstract Window Toolkit file dialog windows must define
public interface java.awt.peer.FileDialogPeer extends java.awt.peer.DialogPeer { // Methods public abstract void setDirectory(String dir); // Sets the directory of the file dialog window to be the specified directory. public abstract void setFile(String file); // Sets the selected file for the file dialog window to be the specified file. public abstract void setFilenameFilter(FilenameFilter filter); // Sets the filename filter for this file dialog window to the specified filter. }
The frame peer interface specifies the methods that all implementations of Abstract Window Toolkit frames must define.
public interface java.awt.peer.FramePeer extends java.awt.peer.WindowPeer { // Methods public abstract void setCursor(int cursorType); public abstract void setIconImage(Image im); public abstract void setMenuBar(MenuBar mb); public abstract void setResizable(boolean resizeable); public abstract void setTitle(String title); } Methods are stated in Table 6.2.
Table 6.2
Method |
Description |
setCursor(int cursorType) |
Sets the cursor image to be one of the predefined cursors. |
setIconImage(Image im) |
Sets the image to display when this frame is iconized. Note that not all platforms support the concept of iconizing a window. |
setMenuBar(MenuBar mb) |
Sets the menubar of this frame to the specified menu bar. |
setResizable(boolean resizeable) |
Determines whether this frame should be resizable. |
setTitle(String title) |
Sets the title of this frame to the specified title. |
The label peer interface specifies the methods that all implementations of Abstract Window Toolkit label must define
public interface java.awt.peer.LabelPeer extends java.awt.peer.ComponentPeer { // Methods public abstract void setAlignment(int alignment); // Sets the alignment for this label to the specified alignment. public abstract void setText(String label); // Sets the text for this label to the specified text. }
The scrolling list peer interface specifies the methods that all implementations of Abstract Window Toolkit scrolling lists must define.
public interface java.awt.peer.ListPeer extends java.awt.peer.ComponentPeer { // Methods public abstract void addItem(String item, int index); public abstract void clear(); public abstract void delItems(int start, int end); public abstract void deselect(int index); public abstract int[] getSelectedIndexes(); public abstract void makeVisible(int index); public abstract Dimension minimumSize(int v); public abstract Dimension preferredSize(int v); public abstract void select(int index); public abstract void setMultipleSelections(boolean v); } Methods are stated in Table 6.3.
Table 6.3
Method |
Description |
addItem(String item, int index) |
Adds the specified string to the scrolling list at the specified position. The index argument is 0-based. If the index is -1, or greater than or equal to the number of items already in the list, then the item is added at the end of the list. |
clear() |
Removes all items from the scrolling list. |
delItems(int start, int end) |
Deletes the items in the range from the scrolling list. |
deselect(int index) |
Deselects the item at the specified index. |
getSelectedIndexes() |
Returns : an array of the selected indexes on the scrolling list. |
makeVisible(int index) |
Forces the item at the specified index to be visible. |
minimumSize(int v) |
Returns : the minimum dimensions needed to display the specified number of rows in a scrolling list. |
preferredSize(int v) |
Returns : the preferred dimensions needed to display the specified number of rows in a scrolling list. |
select(int index) |
Selects the item at the specified index. |
setMultipleSelections(boolean v) |
Sets whether this scolling list allows multiple selections. |
The menu bar peer interface specifies the methods that all implementations of Abstract Window Toolkit menu bars must define.
public interface java.awt.peer.MenuBarPeer extends java.awt.peer.MenuComponentPeer { // Methods public abstract void addHelpMenu(Menu m); // Sets the help menu on the menu bar to be the specified menu. public abstract void addMenu(Menu m); // Adds the specified menu to the menu bar public abstract void delMenu(int index); // Removes the menu located at the specified index from the menu bar. }
The menu component peer interface specifies the methods that all implementations of Abstract Window Toolkit menu components must define.
public interface java.awt.peer.MenuComponentPeer { // Methods public abstract void dispose(); // Disposes of the menu component peer and any resources used by it. }
The MenuItemPeer interface specifies the methods that all implementations of Abstract Window Toolkit menu items must define.
public interface java.awt.peer.MenuItemPeer extends java.awt.peer.MenuComponentPeer { // Methods public abstract void disable(); // Disables this menu item. It can no longer be selected by the user.. public abstract void enable(); // Enables this menu item. It can be selected by the user. public abstract void setLabel(String label); // Changes the menu item's label to be the specified string. }
The menu peer interface specifies the methods that all implementations of Abstract Window Toolkit menus must define.
public interface java.awt.peer.MenuPeer extends java.awt.peer.MenuItemPeer { // Methods public abstract void addItem(MenuItem item); // Adds the specified menu item to this menu. public abstract void addSeparator(); // Adds a separator line to this menu. public abstract void delItem(int index); // Deletes the item at the specified index from this menu. }
The panel peer interface specifies the methods that all implementations of Abstract Window Toolkit panels must define.
public interface java.awt.peer.PanelPeer extends java.awt.peer.ContainerPeer { }
The scroll bar peer interface specifies the methods that all implementations of Abstract Window Toolkit scroll bars must define.
public interface java.awt.peer.ScrollbarPeer extends java.awt.peer.ComponentPeer { // Methods public abstract void setLineIncrement(int l); /* Sets the line increment of the scroll bar. The line increment is the value that is added to or subtracted from the value of the scrollbar when the user hits the line down or line up gadget. */ public abstract void setPageIncrement(int l); /* Sets the page increment of the scroll bar. The page increment is the value that is added to or subtracted from the value of the scrollbar when the user hits the page down or page up gadget. */ public abstract void setValue(int value); // Sets the value of the scroll bar to the specified value. public abstract void setValues(int value, int visible int min, int max ); // Sets several parameters of the scroll bar simultaneously. }
The text area peer interface specifies the methods that all implementations of Abstract Window Toolkit text areas must define
public interface java.awt.peer.TextAreaPeer extends java.awt.peer.TextComponentPeer { // Methods public abstract void insertText(String txt, int pos); // Inserts the specified text at the specified position. public abstract Dimension minimumSize(int rows, int cols); // Returns : the minimum dimensions needed for the text area. public abstract Dimension preferredSize(int rows, int cols); // Returns : the preferred dimensions needed for the text area. public abstract void replaceText(String txt, int start, int end); /* Replaces the text from the start (inclusive) index to the end (exclusive) index with the new text specified. */ }
The text component peer interface specifies the methods that all implementations of Abstract Window Toolkit text components must define
public interface java.awt.peer.TextComponentPeer extends java.awt.peer.ComponentPeer { // Methods public abstract int getSelectionEnd(); // Returns : selected text's end position. public abstract int getSelectionStart(); // Returns : selected text's start position. public abstract String getText(); // Returns : the text of this text component. public abstract void select(int selStart, int selEnd); // Selects the text in the text component from the start (inclusive) index to the end (exclusive) index. public abstract void setEditable(boolean editable) /* Sets the text component to be user editable if the boolean argument is true. If the flag is false, sets the text component so that the user cannot change its contents. */ public abstract void setText(String l); /* Sets the text of this text component to the specified text. }
The text field peer interface specifies the methods that all implementations of Abstract Window Toolkit text fields must define.
public interface java.awt.peer.TextFieldPeer extends java.awt.peer.TextComponentPeer { // Methods public abstract Dimension minimumSize(int cols); /* Returns : the minimum dimensions needed to display the text field with the specified number of columns. */ public abstract Dimension preferredSize(int cols); /* Returns : the preferred dimensions needed to display the text field with the specified number of columns. */ public abstract void setEchoCharacter(char c); /* Sets the echo character for this text field. Any character that the user types in the text field is echoed in the text field as the echo character. An echo character is useful for fields where the user input shouldn't be echoed to the screen such as in the case of a text field for typing in a password. */ }
The window peer interface specifies the methods that all implementations of Abstract Window Toolkit windows must define.
public interface java.awt.peer.WindowPeer extends java.awt.peer.ContainerPeer { // Methods public abstract void toBack(); // Sends this window to the back. public abstract void toFront(); // Brings this window to the front. }