ErrorScreen.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 javax.microedition.lcdui.StringItem;
import com.nokia.example.capitals.CapitalMIDlet;

/**
 * Simple class to display an error screen
 */
public class ErrorScreen extends Screen {

    private Command exitCommand, backCommand;

    public ErrorScreen(CapitalMIDlet midlet, String errorString) {
        super(midlet);

        // create displayable
        Form f = new Form("Error");
        f.append(new StringItem("Value", errorString));
        displayable = f;

        // add commands
        exitCommand = new Command("Exit", Command.EXIT, 0);
        backCommand = new Command("Back", Command.BACK, 0);
        displayable.addCommand(exitCommand);
        displayable.addCommand(backCommand);

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

    public void commandAction(Command c, Displayable d) {
        if (c == exitCommand) {
            midlet.quit();
        } else if (c == backCommand) {
            // Go back
            midlet.showMainScreen();
        }
    }
}