Results 1 to 10 of 10
  1. #1
    Kakashi is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default Confermation Alert with image

    Hi I have been working with this code and trying to mode it from a book to show an image that wants to confirm if an item from a list wants to be delete or not

    Java Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.util.*;
    
    public class ToDoListMidlet extends MIDlet implements CommandListener {
    
        private Form toDoListForm;
    
        private Command addCmd;
        private Command deleteCmd;
        private Command OKCmd;
        private Command BACKCmd;
    
        private DeleteToDoItemsView deleteToDoItemsView;
       
        private Alert myAlert = null;
        
        private AddToDoItemView addToDoItemView;
    
        private Model toDoListModel;
        //for the alert thingy
        private Alert alert;
    
        public ToDoListMidlet(){
    
                // Firt get a blank user form
                toDoListForm = new Form("To Do List");
    
                deleteToDoItemsView = new DeleteToDoItemsView();
                addToDoItemView = new AddToDoItemView();
    
                toDoListModel = new Model();
    
                addCmd = new Command("Add", Command.EXIT, 1);
                deleteCmd = new Command("Delete", Command.SCREEN, 1);
                OKCmd = new Command("OK", Command.SCREEN, 1);
                BACKCmd = new Command("BACK", Command.BACK, 1);
    
                alert = new Alert("Title", "Alert Text", null, AlertType.CONFIRMATION);
                // Set up event handlers to process user commands
                toDoListForm.setCommandListener(this);
        }
    
    
        public void startApp() {
    
                deleteToDoItemsView.createView(toDoListForm, toDoListModel.getToDoListModelData());
    
                toDoListForm.addCommand(addCmd);
                toDoListForm.addCommand(deleteCmd);
    
                // Display initial form
                Display.getDisplay(this).setCurrent(toDoListForm);
              
    
        }
    
        public void pauseApp() {
        }
    
        public void destroyApp(boolean unconditional) {
        }
    
        public void commandAction(Command cmd, Displayable dsp){
    
            if (cmd == addCmd){
                toDoListForm.removeCommand(addCmd);
                toDoListForm.removeCommand(deleteCmd);
                addToDoItemView.createView(toDoListForm, deleteToDoItemsView.getToDoListViewDataString());
                toDoListForm.addCommand(OKCmd);
                toDoListForm.addCommand(BACKCmd);
    
          }else if (cmd == deleteCmd){
                toDoListModel.setToDoListModelData(deleteToDoItemsView.getToDoListViewData());
                deleteToDoItemsView.createView(toDoListForm, toDoListModel.getToDoListModelData());
                
          } else if (cmd == OKCmd){
                toDoListForm.removeCommand(OKCmd);
                toDoListForm.removeCommand(BACKCmd);
                toDoListModel.addToDoItemToModel(addToDoItemView.getToDoItemViewData());
                deleteToDoItemsView.createView(toDoListForm, toDoListModel.getToDoListModelData());
                toDoListForm.addCommand(addCmd);
                toDoListForm.addCommand(deleteCmd);
    
          } else if (cmd == BACKCmd){
                toDoListForm.removeCommand(OKCmd);
                toDoListForm.removeCommand(BACKCmd);
                deleteToDoItemsView.createView(toDoListForm, toDoListModel.getToDoListModelData());
                toDoListForm.addCommand(addCmd);
                toDoListForm.addCommand(deleteCmd);
          }
      }
        
     }
    so I have this and now I want to creat a alert I have been looking at this code to add an image to the file but I cant figure out how to add them togeather :(
    Java Tips - How to show an Alert containing an Image
    Thanks for any help that any one can give me

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Where you stuck with? Because that article clearly explain what you want to do is. Only thing you've to do is, in correct location call that createAlert method with correct resources.

  3. #3
    Kakashi is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default

    It is the image I am stuck with because I got the alert message fixed by adding these methods
    Java Code:
     protected void showConfirmation(String title, String text) {
            alert = new Alert(title, text, null, AlertType.CONFIRMATION);
            alert.addCommand(new Command ("Yes", Command.OK, 1));
            alert.addCommand(new Command("No", Command.CANCEL, 1));
            alert.setCommandListener(new CommandListener() {
    
                public void commandAction(Command c, Displayable d) {
                    if (c.getLabel().equals("Yes")) {
                        notifyDestroyed();
                    }
                    if (c.getLabel().equals("No")) {
                        closeAlert();
                    }
                }
            }) ;
    
    
            Display.getDisplay(this).setCurrent(alert, toDoListForm);
        }
         private void closeAlert() {
            Display.getDisplay(this).setCurrent(toDoListForm);
            alert = null;
        }
    but now when I select the yes it does it but it also closes the app, also when I hit no it still deleats the item on the list. I know that I missing some thing here.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    Kakashi is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default

    I am calling it though the
    Java Code:
    public void commandAction(Command cmd, Displayable dsp){
    
            if (cmd == addCmd){
                toDoListForm.removeCommand(addCmd);
                toDoListForm.removeCommand(deleteCmd);
                addToDoItemView.createView(toDoListForm, deleteToDoItemsView.getToDoListViewDataString());
                toDoListForm.addCommand(OKCmd);
                toDoListForm.addCommand(BACKCmd);
    
          }else if (cmd == deleteCmd){
              showConfirmation("Confirmation", "Do you really want to delete?");
                toDoListModel.setToDoListModelData(deleteToDoItemsView.getToDoListViewData());
                deleteToDoItemsView.createView(toDoListForm, toDoListModel.getToDoListModelData());
    
          } else if (cmd == OKCmd){
                toDoListForm.removeCommand(OKCmd);
                toDoListForm.removeCommand(BACKCmd);
                toDoListModel.addToDoItemToModel(addToDoItemView.getToDoItemViewData());
                deleteToDoItemsView.createView(toDoListForm, toDoListModel.getToDoListModelData());
                toDoListForm.addCommand(addCmd);
                toDoListForm.addCommand(deleteCmd);
    
          } else if (cmd == BACKCmd){
                toDoListForm.removeCommand(OKCmd);
                toDoListForm.removeCommand(BACKCmd);
                deleteToDoItemsView.createView(toDoListForm, toDoListModel.getToDoListModelData());
                toDoListForm.addCommand(addCmd);
                toDoListForm.addCommand(deleteCmd);
          }
      }
    I thin my problem is it is still running thought the deletion process and then exiting if I say yes and if I say no it still deleates the item from the list.

  6. #6
    Kakashi is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default

    Ha ha ha yeah i got the stupid thing working I just had to move some thing around like this;
    Java Code:
       public void commandAction(Command c, Displayable d) {
                    if (c.getLabel().equals("Yes")) {
                         toDoListModel.setToDoListModelData(deleteToDoItemsView.getToDoListViewData());
                         deleteToDoItemsView.createView(toDoListForm, toDoListModel.getToDoListModelData());
                         closeAlert();
                    }
                    if (c.getLabel().equals("No")) {
                        closeAlert();
                    }
                }
            }) ;
    now the alert is working and now I will try to get the image into the code for a more personal touch :) Thanks for the help I am pretty new at this coding stuff.

  7. #7
    Kakashi is offline Member
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default

    I am having trouble with getting the image into the code, i have seen the image created like this
    image = Image.createImage( "/kakashi_Confirm.PNG");
    is this right?

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

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

    Default

    There's no Toolkit in Java ME

    db

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Javascript Alert
    By mutuah in forum New To Java
    Replies: 4
    Last Post: 03-25-2010, 05:28 PM
  2. Session Timeout alert message
    By hemendra.rathore in forum Advanced Java
    Replies: 1
    Last Post: 11-03-2008, 07:03 AM
  3. mouse click alert
    By amir in forum AWT / Swing
    Replies: 1
    Last Post: 08-05-2008, 10:42 PM
  4. Using Alert in MIDlet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-22-2007, 10:22 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
  •