×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    214

    Unhappy [merged] Can anyone help me j2me programming

    How to give a error message when selected more than 3 objects . I have 4 checkboxes if anyone selects all it should give a message as select "only three" in j2me programming the code for design of 4 checkbox is as follows


    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;


    public class CheckBoxExample extends MIDlet implements CommandListener
    {
    private Display display;
    private Form form;
    private Command exit, choose;
    private ChoiceGroup technology;
    private int index;


    public CheckBoxExample()
    {
    form = new Form("Technologies");
    technology = new ChoiceGroup("Select Technology Which You Know", Choice.MULTIPLE);
    exit = new Command("Exit", Command.EXIT, 1);
    choose = new Command("Choose", Command.SCREEN, 2);
    }

    public void startApp()
    {
    display = Display.getDisplay(this);
    technology.append("JAVA", null);
    technology.append("J2ME", null);
    technology.append("J2EE", null);
    technology.append("JSF", null);
    index = form.append(technology);
    form.addCommand(exit);
    form.addCommand(choose);
    form.setCommandListener(this);
    display.setCurrent(form);
    }
    public void pauseApp()
    {
    }

    public void destroyApp(boolean unconditional)
    {
    notifyDestroyed();
    }

    public void commandAction(Command c, Displayable displayable)
    {
    String label = c.getLabel();
    if (label.equals("Choose"))
    {
    StringItem message[] = new StringItem[technology.size()];
    boolean get[] = new boolean[technology.size()];
    technology.getSelectedFlags(get);
    for (int i = 0; i < get.length; i++)
    {
    if (get[i])
    {
    message[i] = new StringItem("Your Choice is: ", technology.getString(i));
    form.append(message[i]);
    }
    }
    form.delete(index);
    form.removeCommand(choose);
    }
    else if (label.equals("Exit"))
    {
    destroyApp(true);
    }
    }
    }

  2. #2
    Registered User
    Join Date
    Dec 2009
    Location
    Bangalore/Mysore, Karnataka, India.
    Posts
    43

    Re: Can anyone help me j2me programming

    Hi,
    This is just one solution, but not an optimum one.

    technology.getSelectedFlags(get);
    int j=0;
    for (int i = 0; i < get.length; i++)
    {
    if (get[i]) j++;
    }
    if(j==get.length-1){
    //Display error message.
    }
    else
    // continue
    }
    -Roopesh.
    (http://trivialdust.blogspot.com/)

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    214

    Re: Can anyone help me j2me programming

    Thank you roopesh.kumar u made my day easier............................

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    214

    Unhappy Can anyone help me in this problem that I face in j2me

    The code I had written for four check boxes is

    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;


    public class CheckBoxExample extends MIDlet implements CommandListener {
    private Display display;
    private Form form;
    private Command exit, choose;
    private ChoiceGroup technology
    ;
    private int index;

    public CheckBoxExample() {
    form = new Form("Technologies");
    technology = new ChoiceGroup("Select Technology Which You Know", Choice.MULTIPLE);
    exit = new Command("Exit", Command.EXIT, 1);
    choose = new Command("Choose", Command.SCREEN, 2);
    }

    public void startApp() {
    display = Display.getDisplay(this);
    technology.append("JAVA", null);
    technology.append("J2ME", null);
    technology.append("J2EE", null);
    technology.append("JSF", null);



    index = form.append(technology);
    form.addCommand(exit);
    form.addCommand(choose);
    form.setCommandListener(this);
    display.setCurrent(form);
    }

    public void pauseApp(){}

    public void destroyApp(boolean unconditional){
    notifyDestroyed();
    }

    public void commandAction(Command c, Displayable displayable){
    String label = c.getLabel();
    if (label.equals("Choose")) {
    StringItem message[] = new StringItem[technology.size()];
    boolean get[] = new boolean[technology.size()];
    technology.getSelectedFlags(get);
    for (int i = 0; i < get.length; i++) {
    if (get[i]) {
    message[i] = new StringItem("Your Choice is: ", technology.getString(i));
    form.append(message[i]);
    }
    }
    form.delete(index);
    form.removeCommand(choose);
    } else if (label.equals("Exit")){
    destroyApp(false);
    }
    }
    }

    when the above program is build then 4 checkboxes appear if we check them the related message comes ...........the task I wanna perform is if 3 checkboxes is checked the 4th checkbox should not be checked instead a warning should appear "select 3 options please" so can anyone help me in this task its very urgent...........

  5. #5
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    1,595

    Re: Can anyone help me in this problem that I face in j2me

    Hello kumar75,

    a similar topic has been discussed here: http://discussion.forum.nokia.com/fo...d.php?t=201851

    Regards,
    r2j7
    [URL="http://library.forum.nokia.com/java"][B] >>> Java Developer's Library <<<[/B][/URL]
    [URL="https://www.developer.nokia.com/Resources/Support/Technical_support.xhtml"] [B]>>> Technical Support for Java ME development <<<[/B][/URL]
    [URL="https://publish.ovi.com/info/"][B]>>> Nokia Publish: reach millions of Nokia users worldwide through Nokia Store <<<[/B][/URL]

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    214

    Unhappy Re: Can anyone help me in this problem that I face in j2me

    Quote Originally Posted by r2j7 View Post
    Hello kumar75,

    a similar topic has been discussed here: http://discussion.forum.nokia.com/fo...d.php?t=201851

    Regards,
    r2j7

    hi tht was me who asked the same doubt I have some more doubts in the same code so I had posted the same code .........please anyone help me in this thread............................

  7. #7
    Registered User
    Join Date
    Dec 2009
    Location
    Bangalore/Mysore, Karnataka, India.
    Posts
    43

    Re: Can anyone help me in this problem that I face in j2me

    Hi Kumar,

    Can you tell me in brief what exactly do you want??
    In the mean time I think this is what you are looking for.
    -Roopesh.
    (http://trivialdust.blogspot.com/)

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    214

    Re: Can anyone help me in this problem that I face in j2me

    Hi can anyone help me displaying the alert when the fourth check box is clicked message "Please select only 3 items" after the alert is given it should go to the main page directly................

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

    Re: Can anyone help me in this problem that I face in j2me

    Quote Originally Posted by kumarv75 View Post
    Hi can anyone help me displaying the alert when the fourth check box is clicked message "Please select only 3 items" after the alert is given it should go to the main page directly................
    Keep on checking the size of the aray that is returned by the
    getSelectedFlags(boolean[]selectedArray_return)
    and if this is greater than 3 then just draw the alert either for the forever or for the couple of seconds.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  10. #10
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: [merged] Can anyone help me j2me programming

    Hi kumarv75,

    Adding to raj one more solution In your screen If only check boxes are there then on each and every key pressed event keep checking if the check boxes are checked ? If it meet your condition perform the operation like displaying the alert

  11. #11
    Registered User
    Join Date
    May 2010
    Posts
    214

    Re: Can anyone help me in this problem that I face in j2me

    boolean get[] = new boolean[technology.size()];
    if(technology.getSelectedFlags(get)== 4 )
    {
    Alert alert = new Alert("Alert", "Please choose only 3 items", null, AlertType.ERROR);
    alert.setTimeout(Alert.FOREVER);
    display.setCurrent(alert, form);

    }
    the above was the code that I added to get an alert message when the fourth element is selected but I am not getting the main screen i.e (the screen with choices )instead the for loop is executed and the result message is executed even for the fourth value selected so can u help me in how to display the main screen after the alert appears

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

    Re: [merged] Can anyone help me j2me programming

    Why dont you give some time to the alert rather then using forever one,
    or did you set the main form/display back when you press the ok command of the alert?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  13. #13
    Registered User
    Join Date
    May 2010
    Posts
    214

    Re: [merged] Can anyone help me j2me programming

    yeah I even tried with this

    if(technology.getSelectedFlags(get)== 4 )
    {
    Alert alert = new Alert("Alert", "Please choose only 3 items", null, AlertType.ERROR);
    alert.setTimeout(Alert.FOREVER);
    display.setCurrent(alert, form);
    form.append(technology);

    }


    to displays the main form but gives a execption threat .....................can u help me please

  14. #14
    Registered User
    Join Date
    May 2010
    Posts
    214

    Re: [merged] Can anyone help me j2me programming

    I even tried with commenting the alert.setTimeout(Alert.FOREVER); but after the message comes it directly executes the for loop not going to the main screen i.e the choice screen

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

    Re: [merged] Can anyone help me j2me programming

    Quote Originally Posted by kumarv75 View Post
    yeah I even tried with this

    if(technology.getSelectedFlags(get)== 4 )
    {
    Alert alert = new Alert("Alert", "Please choose only 3 items", null, AlertType.ERROR);
    alert.setTimeout(Alert.FOREVER);
    display.setCurrent(alert, form);
    form.append(technology);

    }
    You have to use the display object and have to set the form as the displayable.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. byte[] data transfer between J2ME and .NET Web Service?
    By kadir950 in forum Mobile Java General
    Replies: 1
    Last Post: 2010-04-30, 08:31
  2. J2ME Bluetooth Programming
    By srpoucse in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2010-04-13, 13:15
  3. Need to use J2ME Polish framework
    By yatin.frankline in forum Mobile Java General
    Replies: 1
    Last Post: 2010-04-07, 11:46
  4. How can the WAP browser communicate to J2ME application?
    By hbfornies in forum Mobile Java General
    Replies: 20
    Last Post: 2007-03-02, 16:32
  5. Bluetooth Programming in J2ME with 6600
    By wing0custom in forum Mobile Java General
    Replies: 3
    Last Post: 2004-02-09, 17:09

Posting Permissions

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