×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    35

    clickable area of an image by j2me

    Hi,
    In my j2me application I have used canvas to display an image in fullscreen.In the image there are four points( rectangular areas ). Now I have to add events to these points. It looks like that those areas will be used as button. How can I select a area of an image and add an event to that area?
    Please help me giving some idea.
    Thanks in advance.

    Amin

  2. #2
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: clickable area of an image by j2me

    well u could divide the image in four areas (so four times four couples of x,y coodinates), and just check when a command (if u're using commandlistener) or button (in canvas) is pressed..
    when the button is pressed u check in which area the pointer is and then u know which "button" has been pressed...

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    35

    Re: clickable area of an image by j2me

    Hi Tiger79,
    The selectable areas are in the middle of the image.
    Is it possible to add button in canvas? I could not find any reference.If possible then please guide me. I hope, it will make my task simpler.
    thanks.
    Amin

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: clickable area of an image by j2me

    Hi mramin05,
    I will give you an idea and here it is -

    Lets say you have to have the four buttons kind of entity and you have to do some action on these respectively...ok

    @ Have four rectangle/image of the shape of the button..
    @ Draw these on some x and y co-ordinated ...correct..
    @ Lets say you draw these in a row like one down another..for example...(Though you can draw in the order in which you want to)

    @ Then take a int varaible called it currentSelection = 0;
    @ start increasing/decreasing this var on every key pressed..ok
    @ take a action on that var value..I mean call/define a method for the every value..correct..


    Please mark that in order to give the look and feel of the selected/non-selected button..please fill the rect of different color..or draw the images for the selection/non-selection..

    I hope these lines can help you in any way..
    For more queries you can write here.
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  5. #5
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: clickable area of an image by j2me

    well,
    to reply to ur question :
    no there is nothing like an inbuilt buttton class for the Canvas...
    But...
    U can make ur own :P or u could use Commands instead of buttons...
    If u want to make buttons u'll have to draw those urself (or use images) and for the rest u can look at the post of raj_j2me...

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    35

    Re: clickable area of an image by j2me

    HI raj_J2ME,
    Thanks for your reply. I have tried according your Idea.

    Quote Originally Posted by raj_J2ME View Post
    Hi mramin05,

    @ Then take a int varaible called it currentSelection = 0;
    @ start increasing/decreasing this var on every key pressed..ok
    @ take a action on that var value..I mean call/define a method for the every value..correct..


    Please mark that in order to give the look and feel of the selected/non-selected button..please fill the rect of different color..or draw the images for the selection/non-selection..
    Now The problem is how can I get the KeyEvent in my canvas class?
    If the down arrow key is pressed then how can I get the event in my canvas class?
    Please guide me.
    Thanks in advanced.
    Amin

  7. #7
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: clickable area of an image by j2me

    Hi,
    Thats quite simple..no need of worry..just.chill.
    @ Well do you know about the keypressed()method..right..this is supposed call every time..as soon as you press a key..ok.
    @ That take a int keyCode as parameter...correct

    you put the system.out.println()..and then you will come to know that that gives the code for every key..

    Just write inn that method -

    if(keyCode == -1 )
    {
    your action for the up key

    }
    else (keyCode == -2)
    {

    // down.


    }
    else (keyCode == -3)
    {

    // left


    }
    else (keyCode == -4)
    {

    // right


    }
    just implement the code for the action of the key..
    Hope these lines can help, you
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    35

    Re: clickable area of an image by j2me

    Hi Raj,
    Thank you for your reply. Yes I could do it according to your Idea.
    Now I have my jar and I can run the program in wareless toolkit. But when I run the program in my mobile the canvas image and button image goes out of screen. problem is the screen size of my mobile.
    I have search for that and found some results.But I am confussed.
    I want a good solution from you, the experts of the forum.
    Please give me a good solution how can I set the canvas fit to any screen size of mobile?

    Quote Originally Posted by raj_J2ME View Post
    Hi,
    Thats quite simple..no need of worry..just.chill.
    @ Well do you know about the keypressed()method..right..this is supposed call every time..as soon as you press a key..ok.
    @ That take a int keyCode as parameter...correct

    you put the system.out.println()..and then you will come to know that that gives the code for every key..

    Just write inn that method -
    Please help me by providing any good idea.
    Thanks in advance.
    Amin

  9. #9
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: clickable area of an image by j2me

    Hi mramin05,
    Well simple problem and the solution will be..in the coming lines below..
    If your images/button area or what so ever is going out of the screen then there is nothing serious..just check the X and the Y co-ordinated where you drawing the same..ok..

    See what I understand is that those x and y you have given as hard code..is it??

    Like this..
    g.drawImage(img,10,10,0);

    define or try to define the x and y as relative to screen width and height..got it..??
    g.drawImage(img,width/4,ht/4,anchor);

    if still your problem is there after doing this then write here..
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. How to convert a JPEG image to a PNG image using J2ME Code
    By hussain_afs in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2007-12-31, 16:48
  2. cature and save image using J2ME?
    By gr8umm in forum Mobile Java General
    Replies: 11
    Last Post: 2007-04-19, 20:48
  3. query on image processing using j2me
    By rj_cybersilver in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2005-02-03, 10:05
  4. Image capturing using MMAPI of J2ME in series 60
    By adhiyal in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2004-10-01, 07:25
  5. Nokia Image Converter
    By davidpurdie in forum General Development Questions
    Replies: 0
    Last Post: 2004-02-18, 15:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •