你好。我想在这里问你一件事。我知道这对你来说可能很容易,但对我来说可能很难。我学习新的 J2ME。我想知道编程语言的基础知识。我有一个这样的案例:
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);
}
}
我想知道如何将图像更改为图像按钮(键功能)。请帮忙
我试图通过按键事件添加代码,但这让我感到困惑
然后我尝试添加图形但是..我认为它只用于画布
这是我的新代码,这是与上次结果相似的结果
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);
}
但问题是..我不知道如何将图像作为按钮。我是 J2me 的新手,请帮忙