Previous    Next    Home    Source Code    Package

  1. We can listen to lots of things besides a JButton. In this example we listen to mouse movements (such as dragging). When the mouse is dragged, a "Hello World" is dragged with with. Unfortunately, it becomes smeared.
  2. Now the applet implements MouseMotionListener, we invoke addMouseMotionListener(this) to init, and we implement mouseDragged and mouseMoved as required by MouseMotionListener. We do not use mouseMoved so it has an empty body. But mouseDragged invokes paint which draws the "Hello World" string to the screen at the mouse coordinates. The font is set large.