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

📄 btgame.java

📁 J2ME手机蓝牙五子棋游戏
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -