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

📄 guiinput.java

📁 Java编写的蓝牙手机遥控器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.game.GameCanvas;

class GUIInput extends GameCanvas
  implements Runnable, CommandListener
{
  private final String helpText = "OK: Left mouse button click \n\rF: Left mouse button click \n\r<: Scroll left \n\r>: Scroll right \n\r^: Scroll up \n\rv: Scroll down \n\rC: Text clear \n\r0: Right mouse button click \n\r1: Text space\n\r3: Text enter \n\r5: Left mouse button click \n\r7: Zoom in \n\r9: Zoom out \n\r#: Text input \n\r";
  private final Alert helpScreen = new Alert("Help", "", null, AlertType.INFO);
  private static byte NUM0 = 0;
  private static byte NUM1 = 1;
  private static byte NUM2 = 2;
  private static byte NUM3 = 3;
  private static byte NUM4 = 4;
  private static byte NUM5 = 5;
  private static byte NUM6 = 6;
  private static byte NUM7 = 7;
  private static byte NUM8 = 8;
  private static byte NUM9 = 9;
  private static byte NUM_LEFT = 10;
  private static byte NUM_RIGHT = 11;
  private static byte NUM_UP = 12;
  private static byte NUM_DOWN = 13;
  private static byte NUM_FIRE = 15;
  private static byte KEY_POUND = 17;
  private final int MODE_TEXT = 0;
  private final int MODE_PIC = 1;
  private final int PACKET_INPUT = 1;
  private final int PACKET_PIC = 2;
  private final int PACKET_UNLOAD = 3;
  private final int PACKET_KEY_RELASE = 4;
  private final int PACKET_TEXTINPUT = 5;
  private final int PACKET_CLEARKEY = 6;
  private final Command SCR_MAIN_BACK_CMD = new Command("Back", 2, 1);
  private final Command SCR_MAIN_OK_CMD = new Command("OK", 4, 1);
  private Applications parent;
  private BluetoothRemoteControl own;
  private Thread t;
  private int mode;
  private int w;
  private int h;
  byte[] picDisplayed;
  private Font font;
  private int fontHeight;
  private int fontWidth;
  private int boxHight;
  private int fontWidthHelp;
  private Image offScreen;
  private Image image;
  int bColor;
  int fColor;
  int borderColor;
  byte[] gameKeyPack;
  private int keyPressCode;
  boolean isGameKeyPressed;
  public int debugKeyPress;
  public int debugKeyRelease;
  private boolean isNewInputText;
  private boolean isNewInputPic;
  private boolean isKeyPress;
  private boolean isKeyRelease;
  private TextBox textInput;

  public GUIInput(Applications paramApplications, BluetoothRemoteControl paramBluetoothRemoteControl)
  {
    super(false);
    this.parent = paramApplications;
    this.own = paramBluetoothRemoteControl;
    setCommandListener(this);
    this.helpScreen.addCommand(this.SCR_MAIN_BACK_CMD);
    this.helpScreen.setTimeout(-2);
    this.helpScreen.setString("OK: Left mouse button click \n\rF: Left mouse button click \n\r<: Scroll left \n\r>: Scroll right \n\r^: Scroll up \n\rv: Scroll down \n\rC: Text clear \n\r0: Right mouse button click \n\r1: Text space\n\r3: Text enter \n\r5: Left mouse button click \n\r7: Zoom in \n\r9: Zoom out \n\r#: Text input \n\r");
    this.helpScreen.setCommandListener(this);
    this.mode = 1;
    this.picDisplayed = new byte[5];
    this.picDisplayed[0] = 1;
    this.picDisplayed[1] = 2;
    this.picDisplayed[2] = 0;
    this.picDisplayed[3] = 1;
    this.picDisplayed[4] = 0;
    if (!(isDoubleBuffered()))
      this.offScreen = Image.createImage(getWidth(), getHeight());
    Display localDisplay = Display.getDisplay(paramBluetoothRemoteControl);
    this.bColor = localDisplay.getColor(0);
    this.fColor = localDisplay.getColor(1);
    this.borderColor = localDisplay.getColor(4);
    if (this.bColor == this.borderColor)
      this.borderColor = this.fColor;
    if (this.bColor == this.fColor)
    {
      this.bColor = 16777215;
      this.fColor = 0;
      this.borderColor = 0;
    }
    this.gameKeyPack = new byte[6];
    this.gameKeyPack[0] = 1;
    this.gameKeyPack[1] = 1;
    this.gameKeyPack[2] = 0;
    this.gameKeyPack[3] = 2;
    this.gameKeyPack[5] = 0;
    this.isGameKeyPressed = false;
    this.debugKeyRelease = 0;
    this.debugKeyPress = 0;
    this.isNewInputText = false;
    this.isNewInputPic = false;
    this.isKeyPress = false;
    this.isKeyRelease = false;
    this.t = new Thread(this);
    this.t.start();
    this.textInput = new TextBox("Text Input", "", 300, 0);
    this.textInput.addCommand(this.SCR_MAIN_BACK_CMD);
    this.textInput.addCommand(this.SCR_MAIN_OK_CMD);
    this.textInput.setCommandListener(this);
    setFullScreenMode(true);
  }

  public void run()
  {
    mainLoop();
  }

  private void mainLoop()
  {
    try
    {
      if (this.isNewInputPic)
      {
        showPicMode();
        this.isNewInputPic = false;
      }
      if (this.isNewInputText)
      {
        showTextMode();
        this.isNewInputText = false;
      }
      if (isShown())
      {
        boolean bool = detectGameKeyStatus();
        if (!(bool))
        {
          if (this.isKeyPress)
          {
            keyIsPressed();
            this.isKeyPress = false;
          }
          if (this.isKeyRelease)
          {
            keyIsReleased();
            this.isKeyRelease = false;
          }
        }
      }
      try
      {
        Thread.sleep(100L);
      }
      catch (InterruptedException localInterruptedException)
      {
      }
    }
    catch (Exception localException)
    {
    }
  }

  public void execute(byte[] paramArrayOfByte, int paramInt)
  {
    switch (paramArrayOfByte[1])
    {
    case 0:
      show();
      break;
    case 1:
      break;
    case 2:
      showPic(paramArrayOfByte, paramInt);
    }
  }

  private void showHelpScreen()
  {
    Display.getDisplay(this.own).setCurrent(this.helpScreen);
  }

  private void showTextBox()
  {
    this.textInput.setString("");
    Display.getDisplay(this.own).setCurrent(this.textInput);
  }

  private void show()
  {
    this.isNewInputText = true;
  }

  private void showPic(byte[] paramArrayOfByte, int paramInt)
  {
    int i;
    try
    {
      i = GUIGeneral.getLengthAtPos(paramArrayOfByte, 2);
      this.image = Image.createImage(paramArrayOfByte, 4, i);
    }
    catch (Exception localException)
    {
    }
    write(this.picDisplayed);
    this.isNewInputPic = true;
  }

  private void showPicMode()
  {
    BluetoothRemoteControl.debug("showPicMode");
    try
    {
      this.mode = 1;
      if ((!(this.helpScreen.isShown())) && (!(this.textInput.isShown())))
      {
        Display.getDisplay(this.own).setCurrent(this);
        repaint();
      }
    }
    catch (Exception localException)
    {
    }
    catch (Error localError)
    {
    }
  }

  private void showTextMode()
  {
    BluetoothRemoteControl.debug("showTextMode");
    this.mode = 0;
    if (!(this.helpScreen.isShown()))
    {
      Display.getDisplay(this.own).setCurrent(this);
      repaint();
    }
  }

  protected void keyPressed(int paramInt)
  {
    BluetoothRemoteControl.debug("keyPressed: " + Integer.toString(paramInt));
    if (!(isGameKey(paramInt)))
    {
      this.keyPressCode = paramInt;
      this.isKeyPress = true;
    }
  }

  private void keyIsPressed()
  {
    BluetoothRemoteControl.debug("keyIsPressed");
    boolean bool = interpretate(this.keyPressCode, 0);
    if (!(bool))
      if (this.parent.leftSoftKey(this.keyPressCode))
        sendFIRE();
      else if (this.parent.rightSoftKey(this.keyPressCode))
        unLoad();
      else if (this.parent.clearKey(this.keyPressCode))
        sendClearKey();
    this.debugKeyPress += 1;
  }

  protected void keyReleased(int paramInt)
  {
    BluetoothRemoteControl.debug("keyReleased");
    if (!(isGameKey(paramInt)))
      this.isKeyRelease = true;
  }

  private void keyIsReleased()
  {
    BluetoothRemoteControl.debug("keyIsReleased");
    sendKeyRelease();
    this.debugKeyRelease += 1;
  }

  protected void hideNotify()
  {
    BluetoothRemoteControl.debug("hideNotify");
  }

  private void addOptions(Graphics paramGraphics)
  {
    this.w = paramGraphics.getClipWidth();
    this.h = paramGraphics.getClipHeight();
    this.font = Font.getFont(0, 0, 8);

⌨️ 快捷键说明

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