WelcomeScreen.java

/*
 * Copyright © 2011 Nokia Corporation. All rights reserved.
 * Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation. 
 * Oracle and Java are trademarks or registered trademarks of Oracle and/or its
 * affiliates. Other product and company names mentioned herein may be trademarks
 * or trade names of their respective owners. 
 * See LICENSE.TXT for license information.
 */
package com.nokia.example.capitals.ui;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;

import com.nokia.example.capitals.CapitalMIDlet;

/**
 * Initial screen. It gives some basic information
 * about the application
 */
public class WelcomeScreen extends Screen {

    private Command okCommand;
    private Command exitCommand;

    public WelcomeScreen(CapitalMIDlet midlet) {
        super(midlet);

        String name = midlet.getAppProperty("MIDlet-Name");
        String version = midlet.getAppProperty("MIDlet-Version");
        Form f = new Form("Capital Service");
        f.append(name);
        f.append(version);
        displayable = f;

        // create command buttons
        okCommand = new Command("OK", Command.OK, 0);
        exitCommand = new Command("Exit", Command.EXIT, 0);

        // add commands to the text box
        displayable.addCommand(okCommand);
        displayable.addCommand(exitCommand);

        // set command listener
        displayable.setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d) {
        if (c == okCommand) {
            // change to Main Screen
            midlet.showMainScreen();
        } else if (c == exitCommand) {
            // initiate exit
            midlet.quit();
        }
    }
}