Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of

Each time this applet is clicked, a counter is incremented and shown.

This class, Click, can run as an applet because it extends the class java.applet.Applet .

It contains one variable, count,....

6 methods .....

and one special code block.

The variable count is of type int, meaning integer, so it can only contain numbers without a fraction. It's initalized at zero.

The first statements executed are the ones inside the Click block, the so-called CONSTRUCTOR, named after the class itself, Click.

The first statement in the constructor says that the applet now running, this particular instance,.....

will have its mouse methods called at the appropriate moments .

Only mouseClicked contains statements, the others are empty.

In the method mouseClicked the variable is incremented by one ....

and we request that the paint method be executed as soon as possible . Notice that it says : REpaint, NOT paint .

Drawing is done in the paint method.

This is converted to a String, to text, automatically.

Starting position.


All mouse methods are similar except for their names.


Because these 5 methods are present in this class,.....

it is said to implement the java.awt.event.MouseListener interface. ( More on interfaces in our Interfacing lesson )

This allows the class to be registered as a MouseListener .




Although the argument, ev, isn't used in this program, the compiler wants us to name it anyway.

You could name it differently :
  mev, msevt, mouse_event,

but NOT like this :
  while, if, break, for, switch, do, public

, because these (and others) are Java keywords.


By declaring the variable count outside the methods it can be used in every method in this class, and it will exist as long as the applet exists.


as used here, is equivalent to :
  count = count + 1 ;


For public and void see the Language and Access lessons.


public void Click ( )
would NOT be recognized as a constructor because of the word void , so its statements would NOT be executed !