×

Discussion Board

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

    Add push button in form

    Hi guys,
    I have a sms sending application. Presently when I run the application a screen is displayed with "Press ok button to Send SMS". When I press ok command, It exicute a method and send sms.
    But Now I want to add a push button in my form.When The user push the button instead of "ok" the sms sendning method will be called.
    This is my code to dispay the String in first screen.

    <code start>
    disp = Display.getDisplay(this);
    back = new Command("back",Command.BACK,2);
    send = new Command("SEND",Command.OK,1);

    Form form = new Form ("Hi, This is Amin");
    strDisplay = new StringItem("", "Press ok to send SMS");
    form.append( strDisplay );
    form.addCommand(send);
    form.addCommand(back);
    form.setCommandListener((CommandListener) this);
    disp.setCurrent(form);

    <code End>

    How can I add a push button in this form?
    Please help me as I am new in j2me.
    Waiting for ur reply.
    Amin

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Add push button in form

    Hi,

    Well one way would be to create an ImageItem that contains the image of the button.
    Or maybe you can use a SVG button (if the device supports JSR-226):
    http://www.forum.nokia.com/info/sw.n...0_Devices.html

    Oh, and when posting code you should use the code tags (there is a button with the # symbol on it) so that the code remains indented and easier to read.

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

    Re: Add push button in form

    Hi Bogdan Galiceanu,
    Thx for ur reply. Can U give me an example how can I
    use Image as button to exicute a method? I have read Image Item but can not understand.
    Please help me.
    Amin

  4. #4
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Add push button in form

    Here's an example:
    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    
    public class MyMidlet extends MIDlet implements CommandListener, ItemCommandListener {
        
        public Form form=new Form("");
        public Command exit=new Command("Exit", Command.EXIT, 1);
        public Display display=Display.getDisplay(this);
        public Command send=new Command("Send", Command.ITEM, 1);
        
        public void startApp() {
            try {
                Image button=Image.createImage("/src/img.jpg");
                ImageItem imageitem=new ImageItem("", button, ImageItem.LAYOUT_CENTER,"");
                form.append(imageitem);
                imageitem.setDefaultCommand(send);
                imageitem.setItemCommandListener(this);
            }
            catch (Exception e) {
            }
            form.addCommand(exit);
            form.setCommandListener(this);
            display.setCurrent(form);
        }
     
        public void pauseApp() {
        }
     
        public void destroyApp(boolean unconditional) {
        }
     
        public void commandAction(Command c, Displayable d) {
            if(c==exit)
                notifyDestroyed();
        }
        public void commandAction(Command c, Item i) {
            if(c==send)
                //Code for sending SMS or whatever operation you want to perform
        }
       
    }

Similar Threads

  1. second form not getting key events
    By krsunil in forum Symbian User Interface
    Replies: 3
    Last Post: 2008-12-10, 10:29
  2. problems in creating multipage form
    By A.Vogel in forum Symbian User Interface
    Replies: 0
    Last Post: 2007-10-02, 08:16
  3. how to add edit menu on the form
    By shafali gupta in forum Symbian User Interface
    Replies: 4
    Last Post: 2005-05-30, 02:39
  4. Is it safe to add new items to form from thread ?
    By kakoskin in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2004-10-12, 09:24
  5. How to add command button on dialog in series 60
    By chitransh_chetan in forum Symbian
    Replies: 1
    Last Post: 2004-03-18, 05:22

Posting Permissions

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