×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    6

    Question KeyEvent for Form in J2ME

    Hi,

    I am newbie for J2ME. I have created my application fully using Form. Now I need to do keypress events in my app. Will be able to do keypress event in Form? I have know that keyPressed() method is found in Canvas class. Is there any way to set key events for the forms in j2me


    Advance Thanks
    Ganga

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

    Thumbs up Re: KeyEvent for Form in J2ME

    Hi,
    Please read CustomItem class.You can append the customitem object on the form.Then you are supposed to implement the keypressed() method that is available in customitem.
    For you reference please find the code,check that whether this can help you or not.
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;

    public class CustomItemMIDlet extends MIDlet implements CommandListener
    {
    private Form form;
    private Command exit;
    private Display display;
    private CustomItemExample customItem;

    public CustomItemMIDlet()
    {
    form = new Form("CustomItem");
    exit = new Command("Exit", Command.EXIT, 0);
    form.append(new CustomItemExample("CustomItem"));
    form.addCommand(exit);
    form.setCommandListener(this);
    }

    public void startApp()
    {
    display = Display.getDisplay(this);
    display.setCurrent(form);
    }

    public void pauseApp()
    {}

    public void destroyApp(boolean unconditional)
    {}

    public void commandAction(Command c, Displayable s)
    {
    if(c.getCommandType() == Command.EXIT)
    notifyDestroyed();
    }
    }

    class CustomItemExample extends CustomItem
    {
    public CustomItemExample(String title)
    {
    super(title);
    }

    public int getMinContentWidth()
    {
    return 100;
    }

    public int getMinContentHeight()
    {
    return 60;
    }

    public int getPrefContentWidth(int width)
    {
    return getMinContentWidth();
    }

    public int getPrefContentHeight(int height)
    {
    return getMinContentHeight();
    }

    public void paint(Graphics g, int w, int h)
    {
    }

    protected void keyPressed(int keyCode)
    {
    System.out.println("code is as - "+keyCode);
    }

    }
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Nokia Developer Champion
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: KeyEvent for Form in J2ME

    Hi,
    U cant handle the keyevent at form. For this u have to use customitem which provides functionality to handle keyevent.
    check out the following link:

    http://www.java2s.com/Tutorial/Java/...CustomItem.htm
    http://www.java-tips.org/java-me-tip...ustomitem.html
    http://developers.sun.com/mobility/m...ps/customitem/

    else u dont have any option except Canvas. For better UI and custom functionality i suggest to use Canvas.
    thanks,
    jitu_goldie..

    KEEP TRYING..

Similar Threads

  1. J2ME or C++ for VoIP on Mobile
    By sandeepkumar03 in forum VoIP
    Replies: 4
    Last Post: 2009-02-02, 10:28
  2. Calling a native c or c++ application from J2ME
    By satyarajasekhar in forum Mobile Java Networking & Messaging & Security
    Replies: 5
    Last Post: 2009-01-02, 12:10
  3. J2ME or C++ for VoIP on Mobile Phone
    By sandeepkumar03 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2008-11-13, 20:14
  4. Acessing voice channel using J2ME
    By diegomello in forum VoIP
    Replies: 1
    Last Post: 2008-10-21, 15:57
  5. Can J2ME be used for sending MMS Message ?
    By seno_ap in forum Mobile Java General
    Replies: 1
    Last Post: 2006-11-24, 14:36

Posting Permissions

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