Extending Button Java Help

Extending Button

The following program creates an applet that displays a button labeled Test Button
When .the button is pressed, the string "action event: "is displayed on the status line 01 the applet viewer or browser, followed by a count of the number of button presses. The program has one top-level class named Button Dem02 that extends Applet  static integer variable named defined and initialized to zero. This records the number of button pushes. The init( ) method i?instantiates My Dutton and adds it to the applet. My Button is an inner class that extends Button. Its constructor, uses super to pass the label of the button to the super class constructor. It calls enable Events( ) so that action events may be received by this object. When iI'1 action event is generated, process Action Event() is called. That method displays a string on the status line and' calls process Action Event() for the super class. Because My Button is an inner class, it has direct access to the show Status( ) method of ButtonDemo2.

'Extending Check box

The following program creates an applet that displays three' check boxes labeled
"Item 1", "Item 2", and "Item 3". When a checkbox  is selected or deselected, a string containing the name and state of that. check box is' displayed on: the status line,of the applet viewer or browser.  The program has one top-level class named Check box Demo2 that extends Applet. Its init( ) method creates three instances of My Checkbox and adds' these .to the applet. MyCheckbox is an inner class that extends Chec kbox. Its constructor uses super to pass the label- of the check box to the super class constructor  call establishments ) .so that item events may be received by this object. When an.item event is generated, teleprocessing( ) is called. That method displays a string on the status line and calls process enlivenment  for the super class.

Extending Choic'e

The following program creates an applet that displays a choice list with items labeled "Red", "Green", and "Blue". When an entry is selected, a string that contains the name of the color is displayed on the status line of the applet viewer or browser. There is one top-level class named Choice Demo2 that Applet. Its init( ) method creates a choice element and adds it to the applet, My Choice is an inner class that extends Choice. It calls so that item events may be received by this object. When an.item event is generated, is called. That method displays a string on status line and calls process Item Event( ) for the super class.

Posted on September 18, 2014 in Using AWT Controls

Share the Story

About the Author

Back to Top
Share This