FiveMIDlet.java
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:3k
源码类别:

J2ME

开发平台:

Java

  1.  
  2. import java.io.IOException;
  3. import javax.microedition.lcdui.*;
  4. import javax.microedition.midlet.MIDlet;
  5. public class FiveMIDlet extends MIDlet
  6.     implements CommandListener
  7. {   
  8.     private Display display;
  9.     private Form frmFive;
  10.     private Image imgLogo;
  11.     private Command cmdExit;
  12.     private Command cmdGo;
  13.     private Command cmdOptions;
  14.     private Command cmdReg;
  15.     private FiveCanvas Five_Canvas;
  16.     private Options options;
  17.     private Reg reg;
  18.     private static String strAbout = "";
  19.     public FiveMIDlet()
  20.     {
  21.         display = Display.getDisplay(this);
  22.         
  23.         frmFive = new Form(null);
  24.         try
  25.         {
  26.             imgLogo = Image.createImage("/Five.png");
  27.         }
  28.         catch(IOException _ex)
  29.         {
  30.             imgLogo = Image.createImage(1, 1);
  31.         }
  32.         frmFive.append(imgLogo);
  33.         frmFive.append("GoBang Game");
  34.         frmFive.append("仅作为学习范例n");
  35.         cmdExit = new Command("退出", 7, 1);
  36.         cmdGo = new Command("开局", 4, 2);
  37.         cmdOptions = new Command("设置", 1, 3);
  38.         cmdReg = new Command("注册", 1, 3);
  39.         frmFive.addCommand(cmdGo);
  40.         frmFive.addCommand(cmdOptions);
  41.         frmFive.addCommand(cmdReg);
  42.         frmFive.addCommand(cmdExit);
  43.         frmFive.setCommandListener(this);
  44.        
  45.         reg = new Reg(this);
  46.         refreshRegInfo();
  47.         Five_Canvas = new FiveCanvas(this, reg);
  48.         options = new Options(this);
  49.     }
  50.     public void startApp()
  51.     {
  52.         display.setCurrent(frmFive);
  53.     }
  54.     public void pauseApp()
  55.     {
  56.     }
  57.     public void destroyApp(boolean flag1)
  58.     {
  59.     }
  60.     public void commandAction(Command c, Displayable s)
  61.     {
  62.         if(c == cmdExit)
  63.         {
  64.             destroyApp(false);
  65.             notifyDestroyed();
  66.         } else
  67.         if(c == cmdGo)
  68.         {
  69.             display.setCurrent(Five_Canvas);
  70.             Five_Canvas.setOptions(options.borderSize(), options.computerFirst(), options.degree());
  71.             Five_Canvas.newStage();
  72.         } else
  73.         if(c == cmdOptions)
  74.             display.setCurrent(options.frmOptions());
  75.         else
  76.         if(c == cmdReg)
  77.         {
  78.             reg.register(display);
  79.             refreshRegInfo();
  80.         }
  81.     }
  82.     public void backHome()
  83.     {
  84.         refreshRegInfo();
  85.         display.setCurrent(frmFive);
  86.     }
  87.     private void refreshRegInfo()
  88.     {
  89.         String sReg = "[Rigstered]n";
  90.         frmFive.addCommand(cmdGo);
  91.       //  frmFive.removeCommand(cmdReg);
  92.     }
  93.     static 
  94.     {
  95.         strAbout = "";
  96.     }
  97. }