130 likes | 395 Views
AWT Components (Chapter 9). Java Certification Study Group January 21, 1999 Mark Roth. Components. java.awt.Component “A component is an object having a graphical representation that can be displayed on the screen and that can interact with the user.” - Javadoc java.awt.MenuComponent
E N D
AWT Components(Chapter 9) Java Certification Study Group January 21, 1999 Mark Roth
Components java.awt.Component “A component is an object having a graphical representation that can be displayed on the screen and that can interact with the user.” - Javadoc java.awt.MenuComponent “The abstract class MenuComponent is the superclass of all menu-related components.” - Javadoc
java.awt.Compoennt Dimension getSize() void setForeground( java.awt.Color ) void setBackground( java.awt.Color ) setFont( java.awt.Font ) setEnabled( boolean ) setSize( width, height ) These Only Work Well for Frames: setBounds( Rectangle ) or (x, y, w, h) setVisible( boolean )
Component Categories (11) Visual Components (4) Container Components (4) Menu Components
Visual Components “…the ones that users can actually see and interact with.” - S. Roberts To Use: Create a new instance Add component to a container
Constructing Visual Components Button( String label ) --> ActionEvent Canvas() --> MouseEvent, MouseMotionEvent, KeyEvent Checkbox( String label, boolean initialState ) --> ItemEvent Choice() --> ItemEvent FileDialog( Frame parent, String title, int mode ) Label( String text, int alignment )
Constructing Visual Components List( int nVisibleRows, boolean multiSelectOk ) --> ItemEvent, ActionEvent ScrollPane( int scrollbarPolicy ) --> MouseEvent, MouseMotionEvent Scrollbar( int orientation, int initialValue, int sliderSize, int minValue, int maxValue ) --> AdjustmentEvent
Constructing Visual TextComponents TextField( String text, int nCols ) TextArea( String text, int nRows, int nCols, int scrollbarPolicy ) Events TextEvent (both, when text is typed) ActionEvent (Enter in TextField)
Constructing Container Components Applet() Frame( String title ) Panel() Dialog()
Menu Components Creation Create a menu bar and attach it to the frame. Create and populate the menu. Attach the menu to the menu bar. Populating the Menu Menu items Check-box menu items Separators Menus
MenuItem( text ) --> ActionEvent CheckBoxMenuItem() --> ItemEvent menu.addSeparator() setHelpMenu() Menu
References • All Material in this Presentation is heavily based on:Roberts, Simon and Heller, Philip, Java 1.1 Certification Study Guide, 1997: SYBEX™. ISBN: 0-7821-2069-5 • Selected portions from JDK 1.1.6 JavaDoc HTML pages.