![]() ![]() ![]() |
|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Training Index
Counting Mouse Clicksby
Exercise
API Docs
About This Short Course
Short Course
Exercises
Help is available for each task.
Task 1Add the instance variable
public void increaseCount() { // update count variable } Task 2Add the method
public int getCount() { // return count variable } Task 3The core event handling classes are in the You can import the package using: import java.awt.event.*; Task 4To handle the command button action event, add the applet itself as an To the class definition, add: implements ActionListener In the b.addActionListener(this);This means that the current object is functioning as the listener, that is, the target, for action events distributed by the source, in this case, the button b .
Thus, this object, that is, the applet, must define the method(s) specified in
the ActionListener interface.
Task 5Define the Implement your actionPerformed method as follows: public void actionPerformed(ActionEvent e) { increaseCount(); repaint(); }Do not call paint() directly; instead, use repaint() ,
which asks AWT to call paint() when possible.
Task 6Define the
public void paint(Graphics g) { g.drawString("Count: " + getCount(), 20, 50); } The environment that instantiates the applet, typically, a browser, will
invokes the
Copyright 1996-2000 jGuru.com. All Rights Reserved. |