📄 frmmain.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package Twins;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;/** * @author Null */public class frmMain extends MIDlet implements CommandListener,ItemStateListener { private boolean midletPaused = false; private TwinsCanvas Game=new TwinsCanvas(); //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0| private Command exitCommand; private Command okCommand; private Form form; private StringItem List; private ChoiceGroup GameType; private Gauge GameTime; private StringItem object; private ChoiceGroup GraphID; //</editor-fold>//GEN-END:|fields|0| /** * The frmMain constructor. */ public frmMain() { Game.Root=this; Game.IsNewGame=true; } //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0| //</editor-fold>//GEN-END:|methods|0| //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize /** * Initilizes the application. * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method. */ private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize // write pre-initialize user code here//GEN-LINE:|0-initialize|1|0-postInitialize // write post-initialize user code here }//GEN-BEGIN:|0-initialize|2| //</editor-fold>//GEN-END:|0-initialize|2| //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction /** * Performs an action assigned to the Mobile Device - MIDlet Started point. */ public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction // write pre-action user code here switchDisplayable(null, getForm());//GEN-LINE:|3-startMIDlet|1|3-postAction // write post-action user code here //GameTime.setValue(Record.LastGameTime/10 -1); }//GEN-BEGIN:|3-startMIDlet|2| //</editor-fold>//GEN-END:|3-startMIDlet|2| //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction /** * Performs an action assigned to the Mobile Device - MIDlet Resumed point. */ public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction // write pre-action user code here//GEN-LINE:|4-resumeMIDlet|1|4-postAction // write post-action user code here }//GEN-BEGIN:|4-resumeMIDlet|2| //</editor-fold>//GEN-END:|4-resumeMIDlet|2| //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch /** * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable. * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately * @param nextDisplayable the Displayable to be set */ public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch // write pre-switch user code here Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch if (alert == null) { display.setCurrent(nextDisplayable); } else { display.setCurrent(alert, nextDisplayable); }//GEN-END:|5-switchDisplayable|1|5-postSwitch // write post-switch user code here }//GEN-BEGIN:|5-switchDisplayable|2| //</editor-fold>//GEN-END:|5-switchDisplayable|2| //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction /** * Called by a system to indicated that a command has been invoked on a particular displayable. * @param command the Command that was invoked * @param displayable the Displayable where the command was invoked */ public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction // write pre-action user code here if (displayable == form) {//GEN-BEGIN:|7-commandAction|1|19-preAction if (command == exitCommand) {//GEN-END:|7-commandAction|1|19-preAction // write pre-action user code here exitMIDlet();//GEN-LINE:|7-commandAction|2|19-postAction // write post-action user code here } else if (command == okCommand) {//GEN-LINE:|7-commandAction|3|22-preAction // write pre-action user code here if (Game==null) { Game=new TwinsCanvas(); //Game.addCommand(exitCommand); //Game.setCommandListener(this); Game.Root=this; } Game.setFullScreenMode(true); Twins.TotalTime=(GameTime.getValue()+1)*10; getDisplay().setCurrent(Game);//GEN-LINE:|7-commandAction|4|22-postAction // write post-action user code here }//GEN-BEGIN:|7-commandAction|5|7-postCommandAction }//GEN-END:|7-commandAction|5|7-postCommandAction // write post-action user code here }//GEN-BEGIN:|7-commandAction|6| //</editor-fold>//GEN-END:|7-commandAction|6| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">//GEN-BEGIN:|18-getter|0|18-preInit /** * Returns an initiliazed instance of exitCommand component. * @return the initialized component instance */ public Command getExitCommand() { if (exitCommand == null) {//GEN-END:|18-getter|0|18-preInit // write pre-init user code here exitCommand = new Command("\u9000\u51FA", Command.EXIT, 0);//GEN-LINE:|18-getter|1|18-postInit // write post-init user code here }//GEN-BEGIN:|18-getter|2| return exitCommand; } //</editor-fold>//GEN-END:|18-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: form ">//GEN-BEGIN:|14-getter|0|14-preInit /** * Returns an initiliazed instance of form component. * @return the initialized component instance */ public Form getForm() { if (form == null) {//GEN-END:|14-getter|0|14-preInit // write pre-init user code here form = new Form("\u5BF9\u5BF9\u78B0", new Item[] { getList(), getGameType(), getGameTime(), getGraphID(), getObject() });//GEN-BEGIN:|14-getter|1|14-postInit form.addCommand(getExitCommand()); form.addCommand(getOkCommand()); form.setCommandListener(this);//GEN-END:|14-getter|1|14-postInit // write post-init user code here form.setItemStateListener(this); }//GEN-BEGIN:|14-getter|2| return form; } //</editor-fold>//GEN-END:|14-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand ">//GEN-BEGIN:|21-getter|0|21-preInit /** * Returns an initiliazed instance of okCommand component. * @return the initialized component instance */ public Command getOkCommand() { if (okCommand == null) {//GEN-END:|21-getter|0|21-preInit // write pre-init user code here okCommand = new Command("\u5F00\u59CB", Command.OK, 0);//GEN-LINE:|21-getter|1|21-postInit // write post-init user code here }//GEN-BEGIN:|21-getter|2| return okCommand; } //</editor-fold>//GEN-END:|21-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: List ">//GEN-BEGIN:|25-getter|0|25-preInit /** * Returns an initiliazed instance of List component. * @return the initialized component instance */ public StringItem getList() { if (List == null) {//GEN-END:|25-getter|0|25-preInit // write pre-init user code here List = new StringItem("", "\u5386\u53F2\u8BB0\u5F55:");//GEN-BEGIN:|25-getter|1|25-postInit List.setLayout(ImageItem.LAYOUT_DEFAULT | ImageItem.LAYOUT_NEWLINE_BEFORE | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_SHRINK | Item.LAYOUT_VSHRINK | Item.LAYOUT_EXPAND | Item.LAYOUT_VEXPAND | Item.LAYOUT_2);//GEN-END:|25-getter|1|25-postInit // write post-init user code here }//GEN-BEGIN:|25-getter|2| return List; } //</editor-fold>//GEN-END:|25-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: GameType ">//GEN-BEGIN:|31-getter|0|31-preInit /** * Returns an initiliazed instance of GameType component. * @return the initialized component instance */ public ChoiceGroup getGameType() { if (GameType == null) {//GEN-END:|31-getter|0|31-preInit // write pre-init user code here GameType = new ChoiceGroup("\u6E38\u620F\u6A21\u5F0F", Choice.POPUP);//GEN-BEGIN:|31-getter|1|31-postInit GameType.append("180 \u79D2\u6BD4\u8D5B", null); GameType.append("\u81EA\u5B9A\u4E49\u65F6\u95F4", null); GameType.setSelectedFlags(new boolean[] { false, false }); GameType.setFont(0, null); GameType.setFont(1, null);//GEN-END:|31-getter|1|31-postInit // write post-init user code here }//GEN-BEGIN:|31-getter|2| return GameType; } //</editor-fold>//GEN-END:|31-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: GameTime ">//GEN-BEGIN:|39-getter|0|39-preInit /** * Returns an initiliazed instance of GameTime component. * @return the initialized component instance */ public Gauge getGameTime() { if (GameTime == null) {//GEN-END:|39-getter|0|39-preInit // write pre-init user code here GameTime = new Gauge("\u6E38\u620F\u8BA1\u65F6(\u79D2):180", true, 99, 18);//GEN-BEGIN:|39-getter|1|39-postInit GameTime.setLayout(ImageItem.LAYOUT_DEFAULT | ImageItem.LAYOUT_NEWLINE_BEFORE | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_SHRINK | Item.LAYOUT_VSHRINK | Item.LAYOUT_EXPAND | Item.LAYOUT_VEXPAND | Item.LAYOUT_2); GameTime.setPreferredSize(20, -1);//GEN-END:|39-getter|1|39-postInit // write post-init user code here }//GEN-BEGIN:|39-getter|2| return GameTime; } //</editor-fold>//GEN-END:|39-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: object ">//GEN-BEGIN:|40-getter|0|40-preInit /** * Returns an initiliazed instance of object component. * @return the initialized component instance */ public StringItem getObject() { if (object == null) {//GEN-END:|40-getter|0|40-preInit // write pre-init user code here object = new StringItem("http://hi.baidu.com/hetaoos\nHeTaoOS@Gmail.com", null);//GEN-LINE:|40-getter|1|40-postInit // write post-init user code here }//GEN-BEGIN:|40-getter|2| return object; } //</editor-fold>//GEN-END:|40-getter|2| //<editor-fold defaultstate="collapsed" desc=" Generated Getter: GraphID ">//GEN-BEGIN:|41-getter|0|41-preInit /** * Returns an initiliazed instance of GraphID component. * @return the initialized component instance */ public ChoiceGroup getGraphID() { if (GraphID == null) {//GEN-END:|41-getter|0|41-preInit // write pre-init user code here GraphID = new ChoiceGroup("\u56FE\u6848\u7C7B\u578B", Choice.POPUP);//GEN-BEGIN:|41-getter|1|41-postInit GraphID.append("QQ", null); GraphID.append("System", null); GraphID.setFitPolicy(Choice.TEXT_WRAP_DEFAULT); GraphID.setSelectedFlags(new boolean[] { true, false }); GraphID.setFont(0, null); GraphID.setFont(1, null);//GEN-END:|41-getter|1|41-postInit // write post-init user code here }//GEN-BEGIN:|41-getter|2| return GraphID; } //</editor-fold>//GEN-END:|41-getter|2| /** * Returns a display instance. * @return the display instance. */ public Display getDisplay () { List.setText(Record.ToString()); GameTime.setValue((Record.LastGameTime/10 -1)); itemStateChanged(GameTime); return Display.getDisplay(this); } /** * Exits MIDlet. */ public void exitMIDlet() { Record.Close(); switchDisplayable (null, null); destroyApp(true); notifyDestroyed(); } /** * Called when MIDlet is started. * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet. */ public void startApp() { if (midletPaused) { resumeMIDlet (); } else { initialize (); startMIDlet (); } midletPaused = false; //Record.Read(); //Record.Split(); //form.append(Record.ToString()); } /** * Called when MIDlet is paused. */ public void pauseApp() { midletPaused = true; } /** * Called to signal the MIDlet to terminate. * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released. */ public void destroyApp(boolean unconditional) { } public void itemStateChanged(Item item) { if(item ==GameType) { if(GameType.getSelectedIndex()==0) { Record.LastGameTime=180; GameTime.setValue(17); GameTime.setLabel("游戏计时(秒):"+((GameTime.getValue()+1)*10)); itemStateChanged(GameTime); //Twins.TotalTime=180; Game.IsNewGame=true; }else { } } if(item ==GameTime) { if(GameTime.getValue()==18-1) { GameType.setSelectedIndex(0,true); }else { GameType.setSelectedIndex(1,true); } GameTime.setLabel("游戏计时(秒):"+((GameTime.getValue()+1)*10)); Record.LastGameTime=(GameTime.getValue()+1)*10; //Twins.TotalTime=(GameTime.getValue()+1)*10; //System.out.println(Twins.TotalTime); Game.IsNewGame=true; } if(item==GraphID) { Twins.GraphID=GraphID.getSelectedIndex(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -