0
私はCustomItemのを拡張するJavaクラスを作成:なぜこの状況では、pointerPressedメソッドは機能しませんか?
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)画像をクリックしようとすると何も起こりませんが、ダイアログが表示されます。
なぜこれらの問題が発生するのですか?
すでにフォーカスが当たっている画像をクリックすると、カーソルを移動できないことに気付きました。フォーカスを取得した画像をクリックしなければ、フォーカスを移動することができます。 –