📄 bluetoothmidlet.java
字号:
package midlet.bluetoothone;
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.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
/**
* <p>蓝牙入门示例</p>
*
* @author 刘光辉
* @version 2009.02.04
*/
public class BluetoothMIDlet extends MIDlet implements CommandListener{
private List list;
private ServerBox server;
private ClientBox client;
protected void startApp() throws MIDletStateChangeException {
list = new List("蓝牙入门示例",List.IMPLICIT);
list.append("服务端", null);
list.append("客户端", null);
list.setCommandListener(this);
Display.getDisplay(this).setCurrent(list);
}
public void showString(String s)
{
Displayable dp = Display.getDisplay(this).getCurrent();
Alert al = new Alert(null, s, null, AlertType.INFO);
al.setTimeout(2000);
Display.getDisplay(this).setCurrent(al, dp);
}
public void showMainMenu(){
Display.getDisplay(this).
setCurrent(list);
}
protected void pauseApp() {
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
public void commandAction(Command c, Displayable d) {
if(c == List.SELECT_COMMAND){
List list = (List) d;
int index = list.getSelectedIndex();
if(index == 0){
if(server == null){
server = new ServerBox(this);
}
server.setString(null);
Display.getDisplay(this).setCurrent(server);
}
else{
//每次都生成新的客户端实例
client = null;
System.gc();
client = new ClientBox(this);
Display.getDisplay(this).setCurrent(client);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -