Settings.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.racer.views;

import com.nokia.example.racer.Main;
import com.nokia.example.racer.views.tracks.EightLoop;
import com.nokia.example.racer.views.tracks.Monza;
import com.nokia.example.racer.views.tracks.Seissenberg;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

public class Settings extends List implements CommandListener{

    private Command back;

    public Settings() {
        super("Select map", List.EXCLUSIVE);
        append("Monza", null);
        append("Seissenberg", null);
        append("Eightloop", null);
        setCommandListener(this);
        back = new Command("OK", Command.BACK , 1);
        addCommand(back);

    }

    public void commandAction(Command cmnd, Displayable dsplbl) {
        if(cmnd == back) {
            int selected = getSelectedIndex();
            System.out.println("Selected:" + selected);
            GameView view = Main.getInstance().getGameView();
            view.cleanTrackResources();
            if(selected == 0) {
                view.setTrack(new Monza(view));
            }else if(selected == 1) {
                view.setTrack(new Seissenberg(view));
            }else if(selected == 2) {
                view.setTrack(new EightLoop(view));
            }
            Main.getInstance().showMenu();
        }
    }


}