Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 15:27, 19 February 2008.

How to create a confirmation dialog in Java ME

From Forum Nokia Wiki

This example shows how to create a confirmation dialog in Java ME by using standard LCDUI Alert class. This dialog could be used for example for confirming closing of a MIDlet.


The full source code for a test MIDlet:

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
 
public class ConfirmationMIDlet extends MIDlet implements CommandListener {
    private Form form;
    private Alert alert;
    private Command exitCommand;
    
    public void startApp() {
        form = new Form("ConfirmationMIDlet");
	exitCommand = new Command("Exit", Command.EXIT, 1);
	form.setCommandListener(this);
	form.addCommand(exitCommand);
        Display.getDisplay(this).setCurrent(form);
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
 
    public void commandAction (Command c, Displayable d) {
        if (c == exitCommand) {
            showConfirmation("Confirmation", "Do you really want to exit?");
        }
    }
    
    private void closeAlert() {
        Display.getDisplay(this).setCurrent(form);
        alert = null;        
    }
    
    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, form);
    }	
}
Related Discussions
Thread Thread Starter Forum Replies Last Post
platformRequest to dial number - poor user experience rob_savageminds Mobile Java Networking & Messaging & Security 3 2007-11-30 06:01
How to Resize the Dialog Box ? s_mehdi76 Symbian User Interface 0 2008-04-10 13:37
problem CAknQueryDialog ListBox muntain General Symbian C++ 16 2007-08-06 16:10
Create Dialog Failed in FEP handle_cn General Symbian C++ 8 2006-09-06 15:11
Launch dialog from another dialog bjorn.rudolfsson Symbian User Interface 2 2003-06-27 09:36
 
Powered by MediaWiki