Implementation

For information about the design and functionality of the MIDlet, see section Design.

Catch touch events by overriding selected Canvas methods. Every event creates a new Point instance whose state depends on the event type.

Note: While the MIDlet draws the worm-like animation for each touch point normally, the animations are all drawn with the same color (yellow, since that is the color for touch points whose ID is 0). To track individual multipoint touch events on Series 40 devices, use the Multipoint Touch API.

    protected void pointerPressed(int x, int y)
    {
        int pointerId = this.getPointerEventId();
        this.addPoint(pointerId, new Point(x, y, Point.PRESSED));
        this.exitButtonPointerDown = this.exitButtonHitTest(x, y);
        this.inactivityCounter[pointerId] = 0;
    }

    protected void pointerDragged(int x, int y)
    {
        int pointerId = this.getPointerEventId();
        this.addPoint(pointerId, new Point(x, y, Point.DRAGGED));
        this.exitButtonPointerDown = this.exitButtonHitTest(x, y);
        this.inactivityCounter[pointerId] = 0;
    }

    protected void pointerReleased(int x, int y)
    {
        int pointerId = this.getPointerEventId();
        this.addPoint(pointerId, new Point(x, y, Point.RELEASED));
        if (this.exitButtonPointerDown && this.exitButtonHitTest(x, y))
        {
            this.inactivityTimer.cancel();
            Display.getDisplay(this.midlet).setCurrent(null);
            this.midlet.notifyDestroyed();
        }
        else
        {
            this.exitButtonPointerDown = false;
        }
        this.inactivityCounter[pointerId] = 0;
    }

In conclusion, this example supports five simultaneous touches and each of them can have a maximum of 25 circles drawn on the screen to create the worm-like animation. When a point is created, it is stored to the correct index of the currentPoints array, depending on the pointer number.