Drag Text Example

This example demonstrates a scripted event listener. The scripted mouseDragged() method is called in response to mouse events in the frame.

Note that the painted text is not preserved when the window is redrawn. To accomplish that you could use the helper class BshCanvas, which provides buffered drawing and also allows for callbacks to a scripted paint() method. See the graph example.

dragText.bsh - Drag text with the mouse
dragText() {
    f = new Frame("Drag in the box");
    f.setFont( new Font("Serif", Font.BOLD, 24) );
    f.setSize(300, 300);
    gc = f.getGraphics();
    mouseDragged( e ) {
        gc.drawString("Drag Me!", e.getX(), e.getY());
    mouseMoved( e ) { }

    f.addMouseMotionListener( this );