📄 bluetoothprobemidlet.java
字号:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.bluetooth.*;
/**
*
* <p>Title: BluetoothProbeMidlet.java</p>
*
* <p>Description: A simple JSR-82 compliant Bluetooth enabled Midlet that
* searches the area for Bluetooth devices, and displays the Bluetooth
* Profiles that they support.</p>
*
* <p>Copyright: Copyright(c) 2005</p>
*
* <p>By: Bruce Hopkinsn</p>
*
* @version 1.0
*/
public class BluetoothProbeMidlet extends MIDlet implements CommandListener {
Form form;
DeviceDiscoverer deviceDiscoverer;
ServiceDiscoverer serviceDiscoverer;
Command exitCommand;
Command findDevicesCommand;
Command serviceSearchCommand;
/**
* A simple constructor
*/
public BluetoothProbeMidlet() {
form = new Form("Bluetooth Probe");
exitCommand = new Command("Exit", Command.EXIT, 0);
findDevicesCommand = new Command("Find", Command.OK, 0);
serviceSearchCommand = new Command("Search", Command.OK, 0);
updateStatus("Welcome to the Bluetooth Probe Application!");
updateStatus("\nClick on the Find button to find Bluetooth devices in the vicinity");
form.addCommand(exitCommand);
form.addCommand(findDevicesCommand);
form.setCommandListener(this);
}
public void startApp() {
Display.getDisplay(this).setCurrent(form);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
/**
* This method takes the input from the phone, and exits the app,
* finds new Bluetooth devices, or searches for services on devices that
* have been already found.
* @param c Command
* @param s Displayable
*/
public void commandAction(Command c, Displayable s) {
if(c.getLabel().equals("Exit")){
notifyDestroyed();
}
if(c.getLabel().equals("Find")){
form.deleteAll();
deviceDiscoverer = new DeviceDiscoverer(this);
form.removeCommand(findDevicesCommand);
}
if(c.getLabel().equals("Search")){
form.deleteAll();
updateStatus("Searching for services...");
for(int i=0; i<deviceDiscoverer.remoteDevices.size(); i++){
serviceDiscoverer = new ServiceDiscoverer(this, (RemoteDevice)deviceDiscoverer.remoteDevices.elementAt(i));
serviceDiscoverer.start();
try{
Thread.sleep(3000);
} catch(Exception e){}
}
}
}
/**
* This method updates the Midlet's form
* @param status String
*/
public void updateStatus(String status){
form.append(new StringItem(null, "\n" + status));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -