为什么pointerPressed方法在这种情况下不起作用?
我创建了一个扩展 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) 不能通过方向键移动光标(设备为阿尔卡特OT-806D),也不能通过触摸屏幕移动光标。 2)当我尝试单击图像时,尽管应该出现对话框,但什么也没有发生!
那么为什么会出现这些问题呢?
I created a java class which extends CustomItem :
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);
}
}
And in a Form I append some items created from this 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();
When I launch the application , then :
1) the cursor cannot be moved by means of the arrow keys ( the device is Alcatel OT-806D ) , nor by means of touching the screen.
2) when I try to click on an image then nothing happens , although the Dialog should appear !
So why do these problems arise ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正尝试从 MIDP CustomItem 显示 LWUIT 对话框,该对话框不受官方支持,并且在许多创造性的方式中必然会失败。您需要在任何给定时刻使用 LWUIT 或使用 LCDUI。
You are trying to show a LWUIT dialog from a MIDP CustomItem, that is not officially supported and is bound to fail in many creative ways. You need to either use LWUIT or use LCDUI at any given moment.