import javax.microedition.lcdui.*; import com.nokia.mid.ui.*; public class HighScore extends FullCanvas { private GameMIDlet parent = null; private MainMenu menu = null; public HighScore(GameMIDlet parent, MainMenu menu) { this.parent = parent; this.menu = menu; } protected void paint(Graphics g) { //Paint the high scores here } public void keyPressed(int keyCode) { if (keyCode != KEY_END) { //selection list to the screen parent.setDisplayable(menu); } } } |
//Text instructions. Text can be written in constructor or in own method. //Developer should remember that also instruction texts should be //internationalized import javax.microedition.lcdui.*; public class Instructions extends Form implements CommandListener { //Command for going next instruction if needed private Command more = new Command( Resources.getString(Resources.ID_GAME_MORE), Command.OK, 1); //Command for going back to the main menu private Command back = new Command("", Command.BACK, 2); private GameMIDlet parent = null; private MainMenu menu = null; public Instructions(String title, GameMIDlet parent, MainMenu menu) { super(title); this.parent = parent; this.menu = menu; this.addCommand(back); this.addCommand(more); this.setCommandListener(this); } public void commandAction(Command p0, Displayable p1) { if (p0 == more) { //go to the next if needed e.g animation parent.setDisplayable(new InstructionAnimation(parent)); } else if (p0 == back) { parent.setDisplayable(menu); } } } //Instruction animation import javax.microedition.lcdui.*; import com.nokia.mid.ui.*; public class InstructionAnimation extends FullCanvas { private GameMIDlet parent = null; public InstructionAnimation(GameMIDlet parent) { this.parent = parent; } protected void paint(Graphics g) { //Do the animation here } public void keyPressed(int keyCode) { if (keyCode == KEY_SOFTKEY1) { //go to the next instruction screen if needed } else if (keyCode == KEY_SOFTKEY2) { //selection list to the screen parent.setDisplayable(new MainMenu( Resources.getString ( Resources.ID_GAME_NAME), List.IMPLICIT, parent)); } } } |
//Text "About" code skeleton import javax.microedition.lcdui.*; public class About extends Form implements CommandListener { //Command for going back to the main menu private Command back = new Command("", Command.BACK, 1); private GameMIDlet parent = null; private MainMenu menu = null; public About(String title, GameMIDlet parent, MainMenu menu) { super(title); this.parent = parent; this.menu = menu; this.addCommand(back); this.setCommandListener(this); } public void commandAction(Command p0, Displayable p1) { if (p0 == back) { parent.setDisplayable(menu); } } } |
/** * A simple class to simulate a resource bundle. * Modify the contents of this class according to the * locales/languages you want your application to support. * In your application, retrieve a string using code such as the * following: * <pre> * <code>String s = Resources.getString(Resources.ID_GAME_NEW); * </code></pre> * Copyright (C) 2002 Nokia Corporation */ public class Resources { // Identifiers for text strings. public static final int ID_GAME_NEW = 0; public static final int ID_GAME_OPTIONS = 1; public static final int ID_GAME_HIGHSCORES = 2; public static final int ID_GAME_INSTRUCTIONS = 3; public static final int ID_GAME_ABOUT = 4; public static final int ID_GAME_CONTINUE = 5; public static final int ID_GAME_BACK = 6; public static final int ID_GAME_MORE = 7; public static final int ID_GAME_EXIT = 8; public static final int ID_GAME_LEVEL = 9; public static final int ID_GAME_SOUNDS = 10; public static final int ID_GAME_VIBRA = 11; public static final int ID_GAME_NAME = 12; // List of supported locales. // The strings are Nokia-specific values // of the "microedition.locale" system property. private static final String[] supportedLocales = { "en", "fi-FI", "fr", "de" }; //NOTE: default language must be the first one //for getString to work! // Strings for each locale, indexed according to the // contents of supportedLocales private static final String[][] strings = { { "New game", "Settings", "High scores", "Instructions", "About","Continue", "Back", "More", "Exit game", "Level", "Sounds","Shakes", "Game name" }, { "Uusi peli", "Asetukset", "Huipputulokset", "Peliohjeet", "Tietoja","Jatka", "Poistu", "Jatka", "Poistu", "Vaikeusaste", "Peli??net", "V?rin?tehosteet", "Pelin nimi" }, { "Nouveau jeu", "Paramètres", "Scores", "Instructions", "A propos","Continuer", "Retour", "Suite", "Sortir", "Niveau", "Sons", "Vibrations", "Jeu nom" }, { "Neues Spiel", "Einstellungen", "Rekord", "Anleitung", "über","Weiter", "Zurück", "Weiter", "Beenden", "Ebene", "Ton", "Vibrationen", "Spiel name" } }; /** * Gets a string for the given key. * @param key Integer key for string * @return The string */ public static String getString(int key) { String locale = System.getProperty("microedition.locale"); if (locale == null) { locale = new String(""); // use empty instead of null } // find the index of the locale id int localeIndex = -1; for (int i = 0; i < supportedLocales.length; i++) { if (locale.equals(supportedLocales)) { localeIndex = i; break; } } // not found if (localeIndex == -1) { // defaults to first language, in this example English return strings[0][key]; } return strings[localeIndex][key]; } } |
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |