📄 mainmidlet.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package org.challenge.chengshi;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import org.challenge.chengshi.display.DisplayMessage;import org.challenge.chengshi.game.GameUI;import org.challenge.chengshi.record.ListRecord;/** * @author challenge */public class MainMidlet extends MIDlet implements CommandListener { /** The messages are shown in this demo this amount of time. */ static final int ALERT_TIMEOUT = 2000; /** A list of menu items */ private static final String[] elements = { "Server", "Client" }; /** Soft button for exiting the MIDlet. */ private final Command EXIT_CMD = new Command("退出", Command.EXIT, 2); /** Soft button for launching a client or sever. */ private final Command OK_CMD = new Command("确定", Command.SCREEN, 1); private final Command BQ_CMD = new Command("版权", Command.SCREEN, 1); /** A menu list instance */ private final List menu = new List("Bluetooth", List.IMPLICIT, elements, null); /** A GUI part of game that publishes images. */ private GameUI gameUI; /** value is true after creating the server/client */ private boolean isInit = false; private final Command ABOUT_CMD=new Command("关于",Command.OK,1); private final Command HELP_CMD=new Command("帮助",Command.HELP,1); private final Command RECORD_CMD=new Command("记录列表",Command.SCREEN,1); private static final String HELP_STR="此游戏属于棋类游戏,上下左右为手机标准的按键,当某一方横或者竖的四的都一样时即为胜方;此游戏分为两个阶段,刚开始时双方可以自由地选择地方下棋,当棋盘上没有空时进入第二阶段,此时双方每人选择一个自己的棋子并去除,然后采用走棋(只可走到相连的位置上)。"; private static final String ABOUT_STR="此游戏源于本人小时候玩过的一个小游戏,具体见帮助!"; private static final String BQ_STR="此游戏属于本人大学毕业设计时所做,禁止用于商用,转载或修改后发布请注明出处;有问题请联系本人EMAIL: yongzwl@sina.com"; /** * Constructs main screen of the MIDlet. */ public MainMidlet() { menu.addCommand(EXIT_CMD); menu.addCommand(OK_CMD); menu.addCommand(ABOUT_CMD); menu.addCommand(HELP_CMD); menu.addCommand(RECORD_CMD); menu.addCommand(BQ_CMD); menu.setCommandListener(this); } /** * Creates the demo view and action buttons. */ public void startApp() { if (!isInit) { show(); } } /** * Destroys the application. */ public void destroyApp(boolean unconditional) { if (gameUI != null) { gameUI.destroy(); } } /** * Does nothing. Redefinition is required by MIDlet class. */ protected void pauseApp() { } /** * Responds to commands issued on "client or server" form. * * @param c command object source of action * @param d screen object containing the item action was performed on */ public void commandAction(Command c, Displayable d) { if (c == EXIT_CMD) { destroyApp(true); notifyDestroyed(); return; }else if(c==ABOUT_CMD){ this.showString(ABOUT_STR); return; }else if(c==HELP_CMD){ this.showString(HELP_STR); return; }else if(c==RECORD_CMD){ new ListRecord(this); return; }else if(c==BQ_CMD){ this.showString(BQ_STR); return ; } switch (menu.getSelectedIndex()) { case 0: gameUI = new GameUI(this,true); break; case 1: gameUI=new GameUI(this,false); break; default: System.err.println("Unexpected choice..."); break; } isInit = true; } /** Shows main menu of MIDlet on the screen. */ public void show() { Display.getDisplay(this).setCurrent(menu); } public void setDisplayable(Displayable display){ Display.getDisplay(this).setCurrent(display); } public void showString(String message){ new DisplayMessage(this,message); } /** * Returns the displayable object of this screen - * it is required for Alert construction for the error * cases. */ Displayable getDisplayable() { return menu; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -