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

📄 guisearch.java

📁 Java编写的蓝牙手机遥控器
💻 JAVA
字号:
import java.util.Vector;
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.Form;
import javax.microedition.lcdui.Gauge;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.Spacer;

final class GUISearch
  implements CommandListener
{
  private final Command SCR_SEARCH_CANCEL_CMD = new Command("Cancel", 2, 2);
  private final Command SCR_CONNECT_CANCEL_CMD = new Command("Cancel", 2, 2);
  private final Command SCR_IMAGES_BACK_CMD = new Command("Back", 2, 2);
  private final Command SCR_MAIN_OK_CMD = new Command("OK", 4, 2);
  private final List listScreen = new List("Bluetooth RC", 3);
  private BluetoothRemoteControl parent;
  private BluetoothClient bt_client;
  private int devicesFound = 0;
  private Gauge activeGauge;

  GUISearch(BluetoothRemoteControl paramBluetoothRemoteControl)
  {
    this.parent = paramBluetoothRemoteControl;
    this.listScreen.addCommand(this.SCR_IMAGES_BACK_CMD);
    this.listScreen.addCommand(this.SCR_MAIN_OK_CMD);
    this.listScreen.setCommandListener(this);
  }

  void registerBluetoothClient(BluetoothClient paramBluetoothClient)
  {
    this.bt_client = paramBluetoothClient;
  }

  public void commandAction(Command paramCommand, Displayable paramDisplayable)
  {
    if (paramCommand == this.SCR_SEARCH_CANCEL_CMD)
    {
      this.bt_client.cancelSearch();
      destroy();
      return;
    }
    if (paramCommand == this.SCR_CONNECT_CANCEL_CMD)
    {
      destroy();
      return;
    }
    if (paramCommand == this.SCR_IMAGES_BACK_CMD)
    {
      destroy();
      return;
    }
    if (paramDisplayable == this.listScreen)
    {
      int i;
      try
      {
        for (i = 0; i < this.listScreen.size(); ++i)
          if (this.listScreen.isSelected(i))
          {
            Form localForm = new Form("Connecting...");
            insertEmptyString(localForm);
            localForm.addCommand(this.SCR_SEARCH_CANCEL_CMD);
            localForm.setCommandListener(this);
            this.activeGauge = new Gauge("Connecting...", false, -1, 2);
            localForm.append(this.activeGauge);
            Display.getDisplay(this.parent).setCurrent(localForm);
            this.bt_client.connectToDevice(i);
            return;
          }
      }
      catch (Exception localException)
      {
      }
    }
  }

  public void reConnect()
  {
    showConnectUI();
    this.bt_client.reConnect();
  }

  private void showConnectUI()
  {
    Form localForm = new Form("Connecting...");
    insertEmptyString(localForm);
    localForm.addCommand(this.SCR_CONNECT_CANCEL_CMD);
    localForm.setCommandListener(this);
    this.activeGauge = new Gauge("Connecting...", false, -1, 2);
    localForm.append(this.activeGauge);
    Display.getDisplay(this.parent).setCurrent(localForm);
  }

  public void startSearching()
  {
    this.devicesFound = 0;
    showSearchUI(this.devicesFound);
    this.bt_client.requestSearch();
  }

  private void showSearchUI(int paramInt)
  {
    Form localForm = new Form("Searching...");
    insertEmptyString(localForm);
    localForm.addCommand(this.SCR_SEARCH_CANCEL_CMD);
    localForm.setCommandListener(this);
    this.activeGauge = new Gauge("Found: " + String.valueOf(paramInt), false, -1, 2);
    localForm.append(this.activeGauge);
    Display.getDisplay(this.parent).setCurrent(localForm);
  }

  private void insertEmptyString(Form paramForm)
  {
    int i = paramForm.getWidth();
    Font localFont = Font.getDefaultFont();
    int j = localFont.getHeight();
    paramForm.append(new Spacer(i, j));
  }

  void destroy()
  {
    this.parent.show();
  }

  void informSearchError(String paramString)
  {
    Alert localAlert = new Alert("Error", paramString, null, AlertType.ERROR);
    localAlert.setTimeout(4000);
    Display.getDisplay(this.parent).setCurrent(localAlert, this.listScreen);
  }

  void informLoadError(String paramString)
  {
  }

  void oneDeviceFound()
  {
    this.devicesFound += 1;
    this.activeGauge.setLabel("Found: " + String.valueOf(this.devicesFound));
  }

  void showDevicesFound(Vector paramVector)
  {
    int j = paramVector.size();
    this.listScreen.deleteAll();
    for (int i = 0; i < j; ++i)
    {
      String str = (String)paramVector.elementAt(i);
      if (str.length() == 0)
        str = "Unknown";
      this.listScreen.append(str, null);
    }
    Display.getDisplay(this.parent).setCurrent(this.listScreen);
  }

  void showFoundDevices()
  {
    Display.getDisplay(this.parent).setCurrent(this.listScreen);
  }

  void connectSuccess()
  {
    this.parent.connectSuccess();
  }
}

⌨️ 快捷键说明

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