Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5959461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:41:16+00:00 2026-05-22T18:41:16+00:00

finally I got the idea how to handle touch and gestures events on Blackberry,

  • 0

finally I got the idea how to handle touch and gestures events on Blackberry, but now I have 2 questions:
1)how to render graphics above another graphis while being able to handle touch events?
2)how to draw simple rectangle on touch event, say CLICK?

My code & screen:

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() {
    }
}

}

touch and gestures sample app

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:41:17+00:00Added an answer on May 22, 2026 at 6:41 pm

    1.) I’m not sure what the question actually is. Can you rephrase it or give an example? I’ll update this answer once there’s something I can figure out.

    2.) Just set a flag on the DOWN event, save the touch coordinates, call invalidate(), and in your paint method check for said flag and if it exists draw the rectangle at/around your coordinates. On the UP event unset the flag, call invalidate(), and you will remove the rectangle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have finally got in my mind what worried me about Dependency Injection and
Well, now that I've finally got my stupid ODBC stuff configured, I took a
I finally got apache2 with mod_wsgi working on Linux (havent much luck with windows
I finally got my permalinks working for Custom Post Types and Taxonomies using `
I finally got maps api implemented into jquery accordion, mainly by changing var map;
I finally got Bootstrap tabs to work. I was wondering if there's a way
I've finally got my Rails Todo List app to display the Todos using Backbone's
So I finally got my boss to approve the use of perl for this
After many hair-pulling frustrations I've finally got one version of the PerlMagick module working
Alright, I finally got this code to work after hours of toiling: Dim path

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.