Java Reference
In-Depth Information
a touch or stylus is used for interaction. Java ME developers should take
touch devices into consideration when designing and planning the user
interaction as more and more touch-enabled devices appear in the market.
According to the MIDP specification, high-level LCDUI widgets do
not receive low-level touch events. LCDUI widgets continue to receive
the same events as before. This section, therefore, applies mostly to
canvas-based MIDlets.
4.6.1 Handling Stylus Events
Stylus events can be detected using the Canvas class, which provides
developers with methods to handle pointer events:
Canvas.hasPointerEvents() indicates whether the device sup-
ports pointer press and release events (e.g., when the user touches the
screen with a stylus).
Canvas.hasPointerMotionEvents() indicates whether the
device supports pointer motion events (e.g., when the user drags
the pointer).
Canvas.pointerDragged(int x, int y) is called when the
pointer is dragged.
Canvas.pointerPressed(int x, int y) is called when the
pointer is pressed.
Canvas.pointerReleased(int x, int y) is called when the
pointer is released.
The pointer events delivery methods are only called while the Canvas
is visible on the screen. CustomItem also supports pointer events and
the way to query for supported input methods is the getInteraction-
Modes() method.
The following snippet of code demonstrates how to handle stylus
events:
{
public class StylusSupportExamplet extends Canvas
// Members
private final TouchPoint pressed = new TouchPoint();
private final TouchPoint released = new TouchPoint();
private final TouchPoint dragged = new TouchPoint();
// Stylus support
// Indicate if pointer and pointer motion events are supported
public boolean supportsStylus() {
return this.hasPointerEvents() && this.hasPointerMotionEvents();
 
Search WWH ::




Custom Search