hallo. I want to ask something to you here. I know this may be easy for you, but this may be difficult for me. I learn new J2ME. I want to know the basics of the programing languages this. I have a case like this:
class DrawImageCanvas extends Canvas {
static Image image;
static Image image2;
static Image image3;
static Image image4;
static Image image5;
static Image image6;
static String string;
int count;
public void paint(Graphics g) {
int width = getWidth();
int height = getHeight();
// Fill the background using black
g.setColor(0xefffff);
g.fillRect(0, 0, width, height);
// Load an image from the MIDlet resources
if (image == null && image2 == null && image3 == null && image4 == null && image5 == null && image6 == null) {
try {
image = Image.createImage("/http.png");
image2 = Image.createImage("/Back.png");
image3 = Image.createImage("/next.png");
image4 = Image.createImage("/refresh.png");
image5 = Image.createImage("/stop.png");
image6 = Image.createImage("/Bookmark.png");
string = new String("Disini tempat halaman web ditampilkan");
} catch (IOException ex) {
g.setColor(0xffffff);
g.drawString("Failed to load image!", 0, 0, Graphics.TOP | Graphics.LEFT);
return;
}
}
g.drawImage(image, 5, 5, Graphics.TOP | Graphics.LEFT);
g.drawImage(image2, 90, 5, Graphics.TOP | Graphics.LEFT);
g.drawImage(image3, 120, 5, Graphics.TOP | Graphics.LEFT);
g.drawImage(image4, 150, 5, Graphics.TOP | Graphics.LEFT);
g.drawImage(image5, 180, 5, Graphics.TOP | Graphics.LEFT);
g.drawImage(image6, 210, 5, Graphics.TOP | Graphics.LEFT);
g.drawString(string, 5, 36, Graphics.TOP | Graphics.LEFT);
}
}
I want to know how do I change the image to be a image button (key function). please help
i have tried to add code with key press event but it make me confused
then i try add GRAPHIC but.. i think it only used at canvas
this is my new code, this is simmilar result as last result
public void startApp() {
display = Display.getDisplay(this);
exit = new Command("Exit", Command.EXIT, 1);
form = new Form("");
form.addCommand(exit);
form.setCommandListener(this);
try {
Image image = Image.createImage("/http.png");
Image image2 = Image.createImage("/Back.png");
Image image3 = Image.createImage("/next.png");
Image image4 = Image.createImage("/refresh.png");
Image image5 = Image.createImage("/stop.png");
Image image6 = Image.createImage("/Bookmark.png");
form.append(new ImageItem(null, image, ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_LEFT, null));
form.append(new ImageItem(null, image2, ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_LEFT, null));
form.append(new ImageItem(null, image3, ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_LEFT, null));
form.append(new ImageItem(null, image4, ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_LEFT, null));
form.append(new ImageItem(null, image5, ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_LEFT, null));
form.append(new ImageItem(null, image6, ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_NEWLINE_AFTER, null));
display.setCurrent(form);
}catch (java.io.IOException e){
System.err.println(e);
}
display.setCurrent(form);
}
but the problem is.. i dont know how to make image as button. i am newbie in J2me please help