btgame.java

来自「一个蓝牙通信对战五子棋的J2ME游戏源代码」· Java 代码 · 共 82 行

JAVA
82
字号
package bluetoochgame;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class BTGame extends MIDlet implements CommandListener{
  private static BTGame instance;
  private MyCanvas mycanvas ;
   private ChoiceGroup  choices;
  private Form         initForm;


  /** Constructor */
  public BTGame() {

    instance = this;
  }



  /** Main method */
  public void startApp() {
    initForm = new Form("Connect 4");

   // Add the peer choice group
   String[] peerNames = { "Server", "Client" };
   choices = new ChoiceGroup("Please select peer type:", Choice.EXCLUSIVE, peerNames, null);
   initForm.append(choices);

   // Add the Exit and Play commands
   Command exitCommand = new Command("Exit", Command.EXIT, 0);
   initForm.addCommand(exitCommand);
   Command playCommand = new Command("Play", Command.OK, 0);
   initForm.addCommand(playCommand);
   initForm.setCommandListener(this);

   // Set the form as the current screen
   Display.getDisplay(this).setCurrent(initForm);

   // Display.getDisplay(this).setCurrent(displayable);
  }

  /** Handle pausing the MIDlet */
  public void pauseApp() {
  }

  /** Handle destroying the MIDlet */
  public void destroyApp(boolean unconditional) {
  }

  /** Quit the MIDlet */
  public static void quitApp() {
    instance.destroyApp(true);
    instance.notifyDestroyed();
    instance = null;
  }

  public void commandAction(Command c, Displayable s) {
    if (c.getCommandType() == Command.EXIT) {
      destroyApp(true);
      notifyDestroyed();
    }
    else if (c.getCommandType() == Command.OK) {
      // Find out which type of peer connection is being used
      String name = choices.getString(choices.getSelectedIndex());

      // Create the game canvas
      if (mycanvas == null) {
        mycanvas = new MyCanvas(Display.getDisplay(this), name);
        Command exitCommand = new Command("Exit", Command.EXIT, 0);
        mycanvas.addCommand(exitCommand);
        mycanvas.setCommandListener(this);

        // Start up the gameCanvas
        mycanvas.start();
      }
    }
  }


}

⌨️ 快捷键说明

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