Results 1 to 3 of 3
  1. #1
    Sasquatch192 is offline Member
    Join Date
    Oct 2009
    Location
    Victoria, Australia
    Posts
    4
    Rep Power
    0

    Question Events in commandAction(command, item) in MIDlet

    Hi,

    I'm having an issue with a Java MIDlet which I am editing in Netbeans 6.9.1.

    The commandAction(command,item) is a Netbeans auto-generated method.
    With the code below, if the strDeleteData text is clicked during runtime then it displays an alert with two options - Yes and No. This works fine, but I'm stuck on the next part.

    The event triggered when either the Yes and No buttons are clicked is getting lost at the top of the commandAction(..,..) method. When either the Yes and No button is clicked, the event is triggered, but when it hits the commandAction method, it doesn't match strDeleteData or any of the other action commands, so the code for this will not be executed.

    I'm stuck on this issue, and as Netbeans is being a pain with guarded line blocks it's making it rather tough.
    So if you could please take a look and let me know if you have any ideas how I can proceed with this, that would be just super!

    Java Code:
    public void commandAction(Command command, Item item) {
            // write pre-action user code here
            if (item == strDeleteData) {
                if (command == itemCommand) {
                    // write pre-action user code here
    
                    Alert deleteAlert1 = new Alert("Warning", "Are you sure you want to delete all saved data?", null, AlertType.WARNING);
                    Command deleteAllYes = new Command("Yes", Command.OK, 1);
                    Command deleteAllNo = new Command("No", Command.CANCEL, 1);
                    deleteAlert1.setTimeout(Alert.FOREVER);
                    deleteAlert1.addCommand(deleteAllYes);
                    deleteAlert1.addCommand(deleteAllNo);
                    deleteAlert1.setCommandListener(this);
    
                    getDisplay().setCurrent(deleteAlert1);
    
                    if(command == deleteAllYes){
                        //code goes here for when Yes is pressed
                        //......
                    }
                    else if(command == deleteAllNo){
                    //code goes here for when No is pressed
                    //...
                    }
     
                    // write post-action user code here
                }
            } else if (item == strSaveNewSubject) {
                //code below for another Command event
            }
    }//end commandAction method

  2. #2
    Sasquatch192 is offline Member
    Join Date
    Oct 2009
    Location
    Victoria, Australia
    Posts
    4
    Rep Power
    0

    Default

    Hi again,

    As I was still unable to solve this issue (and I'm guessing those who also read this weren't able to assist), I went with an alternative solution that reaches the same outcome.
    Instead of having an alert displaying yes/no to confirm delete; I created a new screen which contained a bigger image, more info explaining the delete process etc and with yes/no buttons. Worked a treat.

    Cheers

    [Edit]
    I forgot to mention, that as this issue is still not solved and the problem could reporoduce again for others; if you can please assist that would be great.

    Thanks
    Last edited by Sasquatch192; 05-01-2011 at 01:42 AM. Reason: Thread still not solved.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,413
    Rep Power
    20

    Default

    Just write your own code until you have enough time to delve into the mysteries of NetBeans visual tools. They're really not targeted at beginners.

    db

Similar Threads

  1. typed events vs untyped events.
    By Drun in forum SWT / JFace
    Replies: 0
    Last Post: 11-23-2009, 12:22 PM
  2. Menu item not working properly for mouse events
    By Preethi in forum New To Java
    Replies: 1
    Last Post: 09-23-2008, 08:56 AM
  3. Adding command buttons on MIDLet Forms
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-22-2007, 09:57 AM
  4. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:23 AM

Posting Permissions

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