Hi ChinLoong,
To my knowledge, there aren't yet any published Java Developer Library Code Examples that combine LWUIT for Series 40 and Gesture Events. Here is a very simple LWUIT MIDlet that displays an empty LWUIT Form on the screen and at the same time, receives Gestures Events:
Main MIDlet:
Code:
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
public class GestureLWUITMIDlet
extends MIDlet {
Form form;
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
Display.init(this);
form = new Form("Nokia LWUIT Components");
Handler handler = new Handler(form);
form.show();
}
}
Supportive GestureHandler class:
Code:
import com.nokia.lwuit.GestureHandler;
import com.nokia.mid.ui.gestures.GestureEvent;
import com.sun.lwuit.Form;
public class Handler
extends GestureHandler {
Handler(Form form) {
GestureHandler.setFormGestureHandler(form, this);
}
public void gestureAction(GestureEvent event) {
int type = event.getType();
switch(type) {
case 49279:
System.out.println("GESTURE_ALL");
break;
case 4:
System.out.println("GESTURE_DRAG");
break;
case 8:
System.out.println("GESTURE_DROP");
break;
case 16:
System.out.println("GESTURE_FLICK");
break;
case 2:
System.out.println("GESTURE_LONG_PRESS");
break;
case 32:
System.out.println("GESTURE_LONG_PRESS_REPEATED");
break;
case 64:
System.out.println("GESTURE_PINCH");
break;
case 32768:
System.out.println("GESTURE_RECOGNITION_START");
break;
case 16384:
System.out.println("GESTURE_RECOGNITION_END");
break;
case 1:
System.out.println("GESTURE_TAP");
break;
}
}
}
Please note that this simple example, only prints the type of the gesture event that the MIDlet has just received in the console (via System.out). Feel free to expand this example by adding your code under each GestureEvent, to cover your use case.