Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Events 黑莓中的图形和触摸事件?_Events_Blackberry_Graphics_Touch - Fatal编程技术网

Events 黑莓中的图形和触摸事件?

Events 黑莓中的图形和触摸事件?,events,blackberry,graphics,touch,Events,Blackberry,Graphics,Touch,最后我想到了如何在Blackberry上处理触摸和手势事件,但现在我有两个问题: 1如何在处理触摸事件的同时在另一个图形上方渲染图形? 2如何在触摸事件上绘制简单的矩形,例如单击 我的代码和屏幕: package mypackage; import net.rim.device.api.lcdui.game.BlackBerryGameCanvas; import net.rim.device.api.system.Bitmap; import net.rim.device.api.ui.Co

最后我想到了如何在Blackberry上处理触摸和手势事件,但现在我有两个问题: 1如何在处理触摸事件的同时在另一个图形上方渲染图形? 2如何在触摸事件上绘制简单的矩形,例如单击

我的代码和屏幕:

package mypackage;

import net.rim.device.api.lcdui.game.BlackBerryGameCanvas;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.TouchGesture;
import net.rim.device.api.ui.VirtualKeyboard;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.TouchEvent;


public class MyScreen extends MainScreen
{   
LabelField touch_type;

public boolean onMenu(int instance) {
    return instance == Menu.INSTANCE_CONTEXT ? false : super.onMenu(instance);
    }

public MyScreen()
{    
    super(NO_SYSTEM_MENU_ITEMS);
    getScreen().getVirtualKeyboard().setVisibility(VirtualKeyboard.HIDE_FORCE);


    VerticalFieldManager vf = new VerticalFieldManager();
    touch_type = new LabelField("SOME TEXT", FIELD_HCENTER);
    vf.add(touch_type);
    vf.add(new HandleTouch());
    add(vf);
}

/*
 * Implementing touch handler class
 */
class HandleTouch extends Field {

    protected void layout(int width, int height) {
        setExtent(360, 460);
    }

    public void paint(Graphics graphics) {
        graphics.drawBitmap(0, 0, this.getWidth(), this.getHeight(), Bitmap.getBitmapResource("bg.png"), 0, 0);
    }

    protected void drawFocus(Graphics g, boolean on) {}

    public boolean isFocusable() { return true;}

    public void drawBall(int x, int y) {

    }

    protected boolean touchEvent(TouchEvent message) {
        switch( message.getEvent() ) {
        case TouchEvent.CLICK:
            int x = message.getGlobalX(1);
            int y = message.getGlobalY(1);

            touch_type.setText("CLICK");
            return true;
        case TouchEvent.DOWN:
            //System.out.println("----------------------------->DOWN");
            touch_type.setText("DOWN");
            return true;    
        case TouchEvent.MOVE:
            //System.out.println("----------------------------->MOVE");
            touch_type.setText("MOVE");
            return true;    
        case TouchEvent.UNCLICK:
            //System.out.println("----------------------------->UNCLICK");
            touch_type.setText("UNCLICK");
            return true;
        case TouchEvent.GESTURE:
            TouchGesture gesture = message.getGesture();
            int gestureCode = gesture.getEvent();
                switch (gestureCode) {
                case TouchGesture.HOVER:
                    //System.out.println("----------------------------->HOVER");
                    touch_type.setText("HOVER");
                    return true;
                case TouchGesture.SWIPE:
                    //System.out.println("----------------------------->SWIPE");
                    touch_type.setText("SWIPE");
                    return true;    
                case TouchGesture.TAP:
                    //System.out.println("----------------------------->TAP");
                    touch_type.setText("TAP");
                    return true;
                case TouchGesture.CLICK_REPEAT:
                    //System.out.println("----------------------------->CLICK REPEAT");
                    touch_type.setText("CLICK REPEAT");
                    return true;
                case TouchGesture.DOUBLE_TAP:
                    //System.out.println("----------------------------->DOUBLE TAP");
                    touch_type.setText("DOUBLE TAP");
                    return true;    
            }   
        }
        //System.out.println("PRINT ME SOMETHING IN ANY CASE");
        super.touchEvent(message);
        return false;
    }

    public HandleTouch() {
    }
}

}

一,。我不确定问题到底是什么。你能重新措辞或举个例子吗?一旦有什么我能弄明白的,我会更新这个答案


二,。只需在DOWN事件上设置一个标志,保存触摸坐标,调用invalidate,然后在绘制方法中检查所述标志,如果存在,则在坐标处/周围绘制矩形。在UP事件中,取消设置标志,调用invalidate,然后删除矩形

这对我更有帮助,我是初学者bb,我可以理解几乎所有的事件。tnx。