Java Programing laungage

J2ME Projects

J2ME Project 1

Creating a J2ME Application for addButton into Form
Previous Home Next

Application for addButton into Form

CommandThe Commands may be implemented in any user interface construct that has semantics for activating a single action.

Command command= new Command(lable, commandType, priority);

label = The label strings are what the application requests to be shown to the user to represent this command

commandType = The application uses the command type to specify the intent of this command

Priority = The application uses the priority value to describe the importance of this command relative to other commands on the same screen. Priority values are integers, where a lower number indicates greater importance.

Button Program


/*
 * Save as a addButton.java
 */
package r4r.Mobile.Basic;

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

/**
 * @author R4R
 */
public class addButton extends MIDlet implements CommandListener {

    /* -- private field -- */
    private Form form;
    private Display display;
    private Command exit, select, help, back;

    /* -- Default constructor -- */
    public addButton() {
        display = Display.getDisplay(this);

        /* -- initialized field -- */
        form = new Form("Add Button into form");
        select = new Command("SELECT", Command.OK, 1);
        exit = new Command("EXIT", Command.EXIT, 1);
        help = new Command("HELP", Command.HELP, 2);
        back = new Command("BACK", Command.BACK, 2);

        /*-- Add button into form --*/
        form.addCommand(select);
        form.addCommand(help);
        form.addCommand(back);
        form.addCommand(exit);
				

        /* -- Add button functionality -- */
        form.setCommandListener(this);
    }

    public void startApp() {
        display.setCurrent(form);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        if (c == exit) {
            destroyApp(true);   // invoked MIDlet to terminate state
            notifyDestroyed(); 
	// notify to application management software that MIDlet
	//has entered into Destroyed state.
        } else if (c == select) {
            // Add select button listner functionality. 
        } else if (c == help) {
            // Add help button listner functionality. 
        } else if (c == back) {
            // Add back button listner functionality. 
        }
    }
}

 

output
Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: