Reputation: 63
I am learning Java Program for Mobile, I am trying to create a program thru which I can show images on screen by dragging from left to right, or right to left.
I have touch screen mobile, no harrdware keyboard.
I am trying the below code in which I have two forms and I want to show the other form when I swip the fingure on screen.
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class ImageDisplay extends MIDlet{
private Display display;
private Form form1,form2;
private Image myImage1,myImage2;
public void startApp(){
display = Display.getDisplay(this);
form1 = new Form ("Image Display");
form2 = new Form("Second Image");
try {
myImage1 = Image.createImage("/bgscaled.jpg");
myImage2 = Image.createImage("/spla77sh.jpg");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
form1.append(myImage1);
form2.append(myImage2);
display.setCurrent(form1);
display.setCurrent(form2);
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
notifyDestroyed();
}
}
Upvotes: 0
Views: 212
Reputation: 18911
You will need to use Canvas instead of the Form
screens as Canvas
has various methods (e.g., pointerDragged
) that can be used to determine touch, release and dragging actions.
Using Canvas
can be a lot of work though (because your code will be responsible for every pixel that is drawn on the display). However, you may find J2ME Polish useful to transfer your Form
UI to Canvas
. (I'm not sure, but J2ME Polish might also take care of the swiping behaviour you are looking for, too.)
Upvotes: 0
Reputation: 4043
You do not have a way to be notified by an LCDUI Form
when a screen swipe happens.
You can add "Next" and "Previous" buttons and change the forms when the buttons are clicked.
Upvotes: 1