1 / 9

Object

Part of the AWT Class Hierarchy. Object. Component. Button. Checkbox. Choice. List. Label. Canvas. TextComponent. Container. Scrollbar. TextArea. TextField. Panel. Window. ScrollPane. Applet. Dialog. Frame. Object.

avon
Télécharger la présentation

Object

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Part of the AWT Class Hierarchy Object Component Button Checkbox Choice List Label Canvas TextComponent Container Scrollbar TextArea TextField Panel Window ScrollPane Applet Dialog Frame

  2. Object Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects implement the methods of this class. Component The Component class is the abstract superclass of many of the AWT classes. It represents something that has a position, a size, can be painted on the screen, and can receive input events. Some Methods Defined in Class Component: setForeground(Color) set the component’s foreground color setBackground(Color) set the component’s background color setFont(Font) set the component’s font paint(Graphics) repaint the component repaint( ) schedule the component for repainting addxxxListener(xxxListener) add an xxx listener for the component (where xxx is Component, Focus, Key, Mouse, or MouseMotion) An xxxListener is an object that waits for an event to occur, then executes certain actions in response to the event.

  3. An Applet Displaying the Components to be Discussed: ComponentIntro1 The Essence of the Structure of the Code of the Nine Applets to be Displayed Next: import java.awt.*; public class Xxx extends java.applet.Applet { <declarations of Components> //in a few cases other stuff public void init() { <Component registration> //using method add(...) and } //in a few cases other stuff } For Component Canvas, an “inner” subclass of class Canvas has been employed that implements method paint(Graphics).

  4. Container The Container class is the abstract superclass representing all components that can hold other components. Some Methods Defined in Class Container: setLayout(LayoutManager) associate a particular layout with the container add(Component) add a component to the container The following components are placed within Container objects: Label Labels A Label object consists of non-editable text. In addition, input events can be associated with the following components: Button Buttons This class creates a labeled button. Checkbox (CheckboxGroup) A check box has an "on" (true) and "off" (false) state. Clicking on the check box toggles its state between "on" and "off ". A group of check boxes in which only 1 can be in its "on" state at any time. CheckBoxes

  5. Choice A choice presents the user with a pop-up menu of choices. The current choice is displayed as the title of the menu. ChoiceLists TextComponent A text component is the superclass of any component that allows the editing of some text. TextArea A text area is a multi-line area for displaying text. It can be set to allow editing or to be read-only. TextAreas TextField A text field presents the user with a single editable line of text. TextFields List A list presents the user with a scrolling list of text items that can be set up either so that the user can pick only 1 item or pick multiple items. ScrollingLists Scrollbar A scroll bar provides a convenient means of allowing a user to select from a range of values. ScrollBars Canvas A Canvas component represents a blank rectangular area of the screen onto which can appear a drawing. Canvases

  6. The Form of the HTML File Used in the Previous 9 Applets: <HTML> <HEAD> <TITLE>Xxx</TITLE> </HEAD> <BODY> <H2>Component: Yyy</H2> <applet code=“Xxx.class" width=www height=hhh> </applet> <P> <A HREF=“Xxx.java"> Java Source </A> </BODY> </HTML> where Xxx is the public class name, Yyy is the component name, and www & hhh represent the applet size.

  7. interface ActionListener (for Button, List, TextField) method: void actionPerformed(ActionEvent) interface ItemListener (for Checkbox, Choice, List) method: void itemStateChanged(ItemEvent) interface AdjustmentListener (for Scrollbar) method: void adjustmentValueChanged(AdjustmentEvent) Methods used in Listening example and/or useful for Homework #4: getSource( ) returns Component, e.g., Button, Choice getActionCommand( ) returns String (applied to Button) setActionCommand(String) getSelectedItem( ) returns String (applied to Choice) getValue( ) returns int (applied to Scrollbar)

  8. An Example that Includes Listeners: Listening Object Model Applet Listening String Label init ( ) paint (Graphics) ActionListener ItemListener ButtonAction Button ButtonAction( ) ActionPerformed (ActionEvent) ChoiceAction Choice ChoiceAction( ) ItemStateChanged (ItemEvent)

  9. ColorAndShape

More Related