SettingsView.java
/*
* Copyright © 2012 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.Oval;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
/*
* A list containing all tracks
*/
public class SettingsView
extends List
implements CommandListener {
private Command back; // back button
/**
* SettingsView constructor. Adds the list items.
*/
public SettingsView() {
super("Select map", List.EXCLUSIVE);
append("Eightloop", null);
append("Monza", null);
append("Oval", null);
setCommandListener(this);
back = new Command("OK", Command.BACK, 1);
addCommand(back);
if (!Main.gesturesSupported) {
setSelectedIndex(0, true);
}
}
/**
* A method that CommandListener must implement. Handles commands.
*
* @param cmnd Command given
* @param dsplbl Displayable where the command is given
*/
public void commandAction(Command cmnd, Displayable dsplbl) {
if (cmnd == back) {
int selected = getSelectedIndex();
GameView view = Main.getInstance().getGameView();
view.cleanTrackResources();
if (selected == 0) {
view.setTrack(new EightLoop(view));
}
else if (selected == 1) {
view.setTrack(new Monza(view));
}
else if (selected == 2) {
view.setTrack(new Oval(view));
}
Main.getInstance().showMenu();
}
}
}