为什么pointerPressed方法在这种情况下不起作用?

时间:2011-06-24 07:26:50

标签: java-me lwuit alcatel-ot

我创建了一个扩展CustomItem的java类:

package view;

import com.sun.lwuit.Dialog;
import javax.microedition.lcdui.CustomItem;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Thumb extends CustomItem {
    private Image theImage;
    public Thumb(Image photo)
    {
        super("");
        theImage = photo;
    }
    private Image createThumbnail(Image image) {
        int sourceWidth = image.getWidth();
        int sourceHeight = image.getHeight();
        int thumbWidth = 64;
        int thumbHeight = -1;

        if (thumbHeight == -1) {
            thumbHeight = thumbWidth * sourceHeight / sourceWidth;
        }

        Image thumb = Image.createImage(thumbWidth, thumbHeight);
        Graphics g = thumb.getGraphics();

        for (int y = 0; y < thumbHeight; y++) {
            for (int x = 0; x < thumbWidth; x++) {
                g.setClip(x, y, 1, 1);
                int dx = x * sourceWidth / thumbWidth;
                int dy = y * sourceHeight / thumbHeight;
                g.drawImage(image, x - dx, y - dy, Graphics.LEFT | Graphics.TOP);
            }
        }
        Image immutableThumb = Image.createImage(thumb);
        return immutableThumb;
    }
    protected int getMinContentHeight() {
        return 64 * theImage.getHeight() / theImage.getWidth();
    }

    protected int getMinContentWidth() {
        return 64;
    }

    protected int getPrefContentHeight(int width) {
        return 64 * theImage.getHeight() / theImage.getWidth();
    }

    protected int getPrefContentWidth(int height) {
        return 64;
    }

    protected void paint(Graphics g, int w, int h) {
        Image transformImage = createThumbnail(theImage);
        g.drawImage(transformImage, 0, 0, Graphics.TOP|Graphics.LEFT);
    }
    protected void pointerPressed(int x, int y)
    {
        Dialog.show("Info", "I clicked the screen !", "ok", null);
    }
}

在表单中,我附加了一些从这个CustomItem创建的项目:

fcDir = (FileConnection) Connector.open("file:///"+pRoot+photoDirectory+"/");
            if (fcDir.exists()) {
                filelist = fcDir.list("*", false);
                while (filelist.hasMoreElements()) {
                    fileName = (String) filelist.nextElement();
                    vPhotoNames.addElement(new String(fileName));
                    FileConnection fcFile = (FileConnection) Connector.open("file:///"+pRoot+photoDirectory+"/"+fileName);
                    // creation customitem
                    this.append(new Thumb(Image.createImage(fcFile.openInputStream())));
                    fcFile.close();
                }
            }
            fcDir.close();

当我启动应用程序时,然后: 1)光标不能通过箭头键(设备是Alcatel OT-806D)移动,也不能通过触摸屏幕。 2)当我尝试点击图像时,没有任何反应,尽管对话框应该出现!

那么为什么会出现这些问题?

1 个答案:

答案 0 :(得分:1)

您正在尝试从MIDP CustomItem显示一个LWUIT对话框,该对话框不受官方支持,并且必然会以许多创造性方式失败。您需要在任何特定时刻使用LWUIT或使用LCDUI。