Mouse Coordinates
Previous    Next    Home    Source Code    Package

  1. In this example we are more interested in determining the position of the mouse as it moves. We implement the MouseMotionListener as before but now non-trivially implement the mouseMoved method to record the mouse position in the JTextFields at the top using the following
       public void mouseMoved (MouseEvent event) {
    Observe that String.valeuOf(...) is used to convert a number obtained from the MouseEvent object called event through the methods getX() and getY().
  2. This example used implements a MousePad class, as a Panel, which gets "bolted" into the applet.