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

📄 connectionmanager.java

📁 這程式是用J2ME撰寫而成
💻 JAVA
字号:
/*wiseremote - a client/server remote control system for wireless devicesCopyright (C) 2005 Martin ProfittlichThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*/import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.IOException;import javax.microedition.io.Connector;import javax.microedition.io.StreamConnection;import javax.bluetooth.*;import javax.microedition.lcdui.*;import java.util.Vector;class ConnectionManager implements DiscoveryListener, CommandListener{  Vector devices;  Vector services;  DiscoveryAgent discoveryAgent;   String url;  public ConnectionManager ()    {      devices = new Vector ();      services = new Vector ();      try        {          LocalDevice localDevice = LocalDevice.getLocalDevice ();          discoveryAgent = localDevice.getDiscoveryAgent ();        }      catch (Exception e)        {          return;        }      try        {          discoveryAgent.startInquiry (DiscoveryAgent.GIAC, this);        }      catch (Exception e)        {          return;        }    }  // DiscoveryListener    public void deviceDiscovered (RemoteDevice btDevice, DeviceClass cod)    {      devices.addElement (btDevice);    }  public void inquiryCompleted (int discType)    {      ConnectionList cl = new ConnectionList ();      cl.setCommandListener (this);      int i;      for (i = 0; i < devices.size (); i++)        {          RemoteDevice d = (RemoteDevice)devices.elementAt (i);          try            {              cl.add (d.getFriendlyName (false));            }          catch (Exception e)            {            }        }      WiseremoteMIDlet.instance.display.setCurrent (cl);    }  public void servicesDiscovered (int transID, ServiceRecord[] servRecord)    {      int i;      for (i = 0; i < servRecord.length; i++)        {          services.addElement (servRecord[i]);        }    }  public void serviceSearchCompleted (int transID, int respCode)    {      ServiceList sl = new ServiceList ();      sl.setCommandListener (this);      int i;      for (i = 0; i < services.size (); i++)        {          ServiceRecord s = (ServiceRecord)services.elementAt (i);          try            {              url = s.getConnectionURL (0, false);              sl.add (url);            }          catch (Exception e)            {            }        }      WiseremoteMIDlet.instance.display.setCurrent (sl);    }    // CommandListener    public void commandAction (Command c, Displayable d)    {      if (c.getLabel () == "Select")        {          if (d instanceof ConnectionList)            {              try                {                  ConnectionList cl = (ConnectionList)d;                  RemoteDevice dev = (RemoteDevice)devices.elementAt (cl.getSelectedIndex ());                  UUID[] sid = new UUID[1];                  sid[0] = new UUID (0x0100);                  discoveryAgent.searchServices (null,                          sid,                          dev,                          this);                  WiseremoteMIDlet.instance.display.setCurrent (new Splash ("Searching for service..."));                }              catch (Exception e)                {                }            }          if (d instanceof ServiceList)            {              try                {                  WiseremoteMIDlet.instance.display.setCurrent (new Splash ("Connecting..."));                  StreamConnection conn = (StreamConnection) Connector.open (url);                  DataInputStream is = conn.openDataInputStream ();                  DataOutputStream os = conn.openDataOutputStream ();                  //os.write (new String ("Login").getBytes (), 0, new String ("Login").length ());                  //os.flush ();                                    WiseremoteMIDlet.instance.protocol = new Protocol (is, os);                  WiseremoteMIDlet.instance.protocol.exec ("Login");                }              catch (IOException e)                {                  // error                  WiseremoteMIDlet.instance.display.setCurrent (new Splash ("Error..."));                }            }        }    }}

⌨️ 快捷键说明

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