![]() ![]() ![]() ![]() | The Anatomy of an Applet |
The Simple applet, like most other applets, overrides theclass Simple extends Applet { . . . public void paint(Graphics g) { . . . } . . . }paint()
method. Thepaint()
method is one of two display methods that the Applet class provides for applets to override:The Applet class also provides a group of methods for event handling:
paint()
- the basic display method; most applets implement this method to draw the applet's representation within a browser page
update()
- a method you can use along with
paint()
to make improvements in drawing performanceAn applet overrides the method corresponding to the event the applet needs to react to. For example, to make the Simple applet respond to mouse clicks, we must add a
keyDown()
- notifies the applet that the user pressed a key on the keyboard
mouseDown()
,mouseUp()
- notify the applet that the user pressed/released a mouse button
mouseEnter()
,mouseExit()
- notify the applet that the cursor entered/exited the applet's display area
mouseDrag()
- notifies the applet that the user moved the mouse while pressing a mouse button
mouseMove()
- notifies the applet that the mouse moved but no mouse button was pressed
mouseDown()
method.Below is the resulting applet. When you click within its rectangle, it displays the word "click!...".public void mouseDown(int x, int y) { addItem("click!... "); }
Drawing and event handling are covered in detail later in this trail, in [PENDING]. For more information on the methods listed above, you can also refer to the Applet API reference page
.
![]() ![]() ![]() ![]() | The Anatomy of an Applet |