⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dictionary.java

📁 J2ME MIDP_Example_Applications
💻 JAVA
字号:
// Copyright 2003 Nokia Corporation.//// THIS SOURCE CODE IS PROVIDED 'AS IS', WITH NO WARRANTIES WHATSOEVER,// EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY, FITNESS// FOR ANY PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE// OR TRADE PRACTICE, RELATING TO THE SOURCE CODE OR ANY WARRANTY OTHERWISE// ARISING OUT OF ANY PROPOSAL, SPECIFICATION, OR SAMPLE AND WITH NO// OBLIGATION OF NOKIA TO PROVIDE THE LICENSEE WITH ANY MAINTENANCE OR// SUPPORT. FURTHERMORE, NOKIA MAKES NO WARRANTY THAT EXERCISE OF THE// RIGHTS GRANTED HEREUNDER DOES NOT INFRINGE OR MAY NOT CAUSE INFRINGEMENT// OF ANY PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OWNED OR CONTROLLED// BY THIRD PARTIES//// Furthermore, information provided in this source code is preliminary,// and may be changed substantially prior to final release. Nokia Corporation// retains the right to make changes to this source code at// any time, without notice. This source code is provided for informational// purposes only.//// Nokia and Nokia Connecting People are registered trademarks of Nokia// Corporation.// Java and all Java-based marks are trademarks or registered trademarks of// Sun Microsystems, Inc.// Other product and company names mentioned herein may be trademarks or// trade names of their respective owners.//// A non-exclusive, non-transferable, worldwide, limited license is hereby// granted to the Licensee to download, print, reproduce and modify the// source code. The licensee has the right to market, sell, distribute and// make available the source code in original or modified form only when// incorporated into the programs developed by the Licensee. No other// license, express or implied, by estoppel or otherwise, to any other// intellectual property rights is granted herein.import javax.microedition.lcdui.*;// This class maps integer id's to Strings used in the user interface// screens of the MIDlet. It is meant as a simple placeholder for// internationalization support.//// Currently, the default (and only) language supported is "en-US".// The class could be extended to support other mappings in the future,// although it currently supports just one.//// (Note: A few simple strings used in CloseableCanvas like ":", "(", ")",// numeric strings, and white space like " " or "\n" are not translated// by the Dictionary. If those would need internationalization support,// then appropriate support would need to be added.)class Dictionary{    // The types of strings used in the MIDlet user interface are:    //   LABEL : short text labels used in simple UI elements like    //           Commands, List StringItems, etc.    //    TEXT : text strings that are 'contents' of some screen, i.e. drawn    //           in the game screen or used in the instructions screen    private static short ix = 0;    final static short LABEL_ABOUT = ix++;    final static short LABEL_BACK = ix++;    final static short LABEL_CONTINUE = ix++;    final static short LABEL_EDIT = ix++;    final static short LABEL_EXIT = ix++;    final static short LABEL_INSTRUCTIONS = ix++;    final static short LABEL_NEWGAME = ix++;    final static short LABEL_MODIFY = ix++;    final static short LABEL_OFF = ix++;    final static short LABEL_ON = ix++;    final static short LABEL_SETTINGS = ix++;    final static short LABEL_SOUND = ix++;    final static short LABEL_VERSION = ix++;    final static short LABEL_VIBRATION = ix++;    final static short TEXT_GAME_BASE_DESTROYED = ix++;    final static short TEXT_GAME_BLOCKS = ix++;    final static short TEXT_GAME_QUIT_PROMPT = ix++;    final static short TEXT_GAME_RESUME_PROMPT = ix++;    final static short TEXT_GAME_LIVES = ix++;    final static short TEXT_GAME_YOU = ix++;    final static short TEXT_GAME_YOU_WON = ix++;    final static short TEXT_GAME_YOU_LOST = ix++;    final static short TEXT_INSTRUCTIONS = ix++;    final static short TEXT_INSTRUCTIONS_GAUGE = ix++;    final static short NUM_IDS = ix;    private static Dictionary instance = null;    private String[] strings;    Dictionary(String locale, String encoding)    {        // If you decide to add additional internationalization support,        // you would need to modify this method, something like this:        //    if (locale.equals("xx-YY"))        //    {        //        strings = stringsXxYY();        //    }        //    else if (locale.startsWith("zz"))        //    {        //        // e.g. might keep the strings a in .dat resource file        //        strings = stringsZz();        //    }        //    else        //    {        //        strings = stringsEnUS(); // use default language        //    }        //        // The strings returned by the 'stringsXxYy()' internationalization        // methods could be defined at compile-time, as in the default        // method stringsEnUs(), or at run-time.        //        // Run-time support would involve reading the strings        // from appropriate resource files added to the MIDlet's .jar file.        // (e.g. "en-UK.dat", "en.dat", "fi-FI.dat", "fi-SE.dat", etc.)        // Such an approach would allow one to separate the process        // of internationalizing strings from the process of compiling the        // MIDlet. (Determining which .dat files are part of a particular        // version of a MIDlet's .jar file, would be part of the        // MIDlet jarring and deployment process.) You may also need        // to used fixed dictionary entry ID's above.        // The only language currently supported is the default one: "us-EN".        strings = stringsEnUS();    }    private String[] stringsEnUS()    {        // USA English strings        String[] strArray = new String[NUM_IDS];        // Labels        strArray[LABEL_ABOUT] = "About";        strArray[LABEL_BACK] = "Back";        strArray[LABEL_CONTINUE] = "Continue";        strArray[LABEL_EDIT] = "Edit";        strArray[LABEL_EXIT] = "Exit";        strArray[LABEL_INSTRUCTIONS] = "Instructions";        strArray[LABEL_MODIFY] = "Modify";        strArray[LABEL_NEWGAME] = "New game";        strArray[LABEL_OFF] = "off";        strArray[LABEL_ON] = "on";        strArray[LABEL_SETTINGS] = "Settings";        strArray[LABEL_SOUND] = "Sound";        strArray[LABEL_VERSION] = "Version";        strArray[LABEL_VIBRATION] = "Vibration";        // Game screen text strings        strArray[TEXT_GAME_BASE_DESTROYED] = "Base destroyed!";        strArray[TEXT_GAME_BLOCKS] = "Blocks";        strArray[TEXT_GAME_LIVES] = "lives";        strArray[TEXT_GAME_RESUME_PROMPT] = "Press a key to resume";        strArray[TEXT_GAME_QUIT_PROMPT] = "Use softkey to quit";        strArray[TEXT_GAME_YOU] = "You";        strArray[TEXT_GAME_YOU_WON] = "You won!";        strArray[TEXT_GAME_YOU_LOST] = "You lost";        // Instructions screen text strings        Canvas c = new CloseableCanvas("");        String up = c.getKeyName(c.getKeyCode(Canvas.UP));        String down = c.getKeyName(c.getKeyCode(Canvas.DOWN));        String left = c.getKeyName(c.getKeyCode(Canvas.LEFT));        String right = c.getKeyName(c.getKeyCode(Canvas.RIGHT));        String fire = c.getKeyName(c.getKeyCode(Canvas.FIRE));        strArray[TEXT_INSTRUCTIONS] =            // Describe game's objective and how to play:            "The objective of the game is for you to get " +            GameManager.GAME_OVER_SCORE +            " points before the blocks do. " +            "Destroying blocks earns you points. " +            "The blocks get points for flying off the screen, " +            "and extra points for hitting or destroying the base.\n\n" +            // Describe block's point values:            "Not all blocks are equally easy to destroy. " +            "The blocks increase in difficulty (and points value) " +            "as follows: empty dark, single white diagonal line, " +            "double white diagonal lines, empty white, " +            "single black diagonal line, " +            "and double black diagonal lines.\n\n" +            "Your score and remaining lives are shown in the upper left " +            "hand corner of the screen. The blocks' score is shown in the " +            "lower right hand corner of the screen. The blocks can win by " +            "scoring " + GameManager.GAME_OVER_SCORE + " points before " +            "you do, or by destroying your base until you have no lives " +            "left.\n\n" +            // Describe keypad usage:            "The default keys to use for the " +            "up, down, left, right and fire game actions are: " +            up + ", " + down + ", " + left + ", " + right + ", and " + fire +            " respectively. This can vary in different phone models.\n\n" +            // Describe softkey usage:            "In the game screen, pressing an appropriate softkey causes " +            "the game to pause. Use '" + strArray[LABEL_CONTINUE] +            "' to return to the game in progress. " +            "Game play will resume when you press a non-softkey.\n\n";        strArray[TEXT_INSTRUCTIONS_GAUGE] =            // Describe gauge            "A gauge may sometimes be shown in the upper right " +            "corner of the screen. " +            "It is used to indicate when the base's laser cannon is " +            "overheating. The cannon may overheat if you continuously " +            "hold down the game's 'fire' button for too long. " +            "When this occurs, the cannon can not be fired again, " +            "until it has cooled down (i.e. until the gauge empties).";        return strArray;    }    String getString(int id)    {        if ((id >= 0) && (id < strings.length))        {            return strings[id];        }        else        {            throw new IllegalArgumentException("id=" + id +                " is out of bounds. max=" + strings.length);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -