我在本教程之后使用bluecove做了一个蓝牙服务器:http://luugiathuy.com/2011/02/android-java-bluetooth/我想在连接之前添加一个带有JOptionPane
的确认弹出窗口,但我不知道怎么做。你能帮助我吗?这是代码:
import com.intel.bluetooth.BluetoothStack;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.UUID;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;
import javax.swing.JOptionPane;
public class WaitThread implements Runnable {
private GestorPrincipal gestor = GestorPrincipal.getInstancia();
/** * Constructor */
public WaitThread() { }
@Override
public void run() {
waitForConnection();
}
/** * Waiting for connection from devices */
private void waitForConnection() {
// retrieve the local Bluetooth device object
LocalDevice local = null;
StreamConnectionNotifier notifier; StreamConnection connection = null;
// setup the server to listen for connection
try {
local = LocalDevice.getLocalDevice();
local.setDiscoverable(DiscoveryAgent.GIAC);
UUID uuid = new UUID(80087355);
// "04c6093b-0000-1000-8000-00805f9b34fb"
String url = "btspp://localhost:" + uuid.toString() + ";name=RemoteBluetooth";
notifier = (StreamConnectionNotifier) Connector.open(url);
}
catch (Exception e) {
e.printStackTrace();
return;
}
// waiting for connection
while (true) {
try {
System.out.println("Esperando la conexion...");
gestor.agregarTexto("Esperando la conexion..");
connection = notifier.acceptAndOpen();
Thread processThread = new Thread(new ProcessConnectionThread(connection));
processThread.start();
}
catch (Exception e) {
e.printStackTrace(); return;
}
}
}
}`
PD:对不起我的英语,我来自ARG。
答案 0 :(得分:0)
Oracle已经详细记录了这个名为"如何制作对话框" 这个文档,该文档展示了如何创建不同类型的对话框,这些对话框会提示用户注意用户的输入还有一些只是用图标显示一些数据。
http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html
根据您的要求,您可以这样做:
val withId = """{"name":"Bob","id":1234}"""
val withoutId = """{"name":"Charlie"}"""
val bob = Json.parse(withId).as[Location]
println(bob)
// Location(Bob,Some(1234))
val charlie = Json.parse(withoutId).as[Location]
println(charlie)
// Location(Charlie,None)