Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * bem10jfx.blogspot.com
- * knbjfx.blogspot.com
- *numagrandeviagem.blogspot.com
- */
- package bluetwo_fx;
- import java.io.IOException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javafx.application.Application;
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableList;
- import javafx.scene.Group;
- import javafx.scene.Scene;
- import javafx.scene.control.ListView;
- import javafx.scene.control.TextArea;
- import javafx.scene.layout.HBox;
- import javafx.scene.paint.Color;
- import javafx.stage.Stage;
- import javax.bluetooth.BluetoothStateException;
- import javax.bluetooth.DeviceClass;
- import javax.bluetooth.DiscoveryAgent;
- import javax.bluetooth.DiscoveryListener;
- import javax.bluetooth.LocalDevice;
- import javax.bluetooth.RemoteDevice;
- import javax.bluetooth.ServiceRecord;
- /**
- *
- * @author kml knb ' s
- */
- public class NewClass extends Application implements DiscoveryListener{
- ObservableList<String> nmpreknown = FXCollections.observableArrayList( "Preknown");
- ListView<String> listViewpreknown = new ListView<String>(nmpreknown);
- ObservableList<String> nmdisc = FXCollections.observableArrayList( "Ativos não pareados");
- ListView<String> listViewdisck = new ListView<String>(nmdisc);
- ObservableList<String> names = FXCollections.observableArrayList( "cached");
- ListView<String> listView = new ListView<String>(names);
- @Override
- public void start(Stage stage) throws IOException {
- stage.setTitle("Blues");
- Group gp=new Group();
- Scene scene=new Scene(gp,800,400,Color.SILVER);
- stage.setScene(scene);
- HBox hb=new HBox(03);
- gp.getChildren().add(hb);
- //adcionar clausula twmorows
- LocalDevice localDevice = null;{try {
- localDevice=LocalDevice.getLocalDevice();
- } catch (BluetoothStateException ex) {
- Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- DiscoveryAgent discoveryAgent;
- discoveryAgent = localDevice.getDiscoveryAgent();
- //remote device
- RemoteDevice remotedevices[];
- RemoteDevice remotedevices_Preknown[];
- remotedevices = discoveryAgent.retrieveDevices(DiscoveryAgent.CACHED);
- hb.getChildren().add(listView);
- if (remotedevices != null) {
- for (int i=0; i < remotedevices.length; i++) {
- names.add("Dispositivos no Cached: " +
- remotedevices[i].getFriendlyName(false) +
- "-id-" +remotedevices[i].getBluetoothAddress() );
- }
- }
- //--------------------------------
- remotedevices_Preknown= discoveryAgent.retrieveDevices(DiscoveryAgent.PREKNOWN);
- hb.getChildren().add(listViewpreknown);
- if (remotedevices_Preknown != null) {
- for (int i=0; i < remotedevices.length; i++) {
- nmpreknown.add("disp.Pareados: " +
- remotedevices_Preknown[i].getFriendlyName(false) +
- " id " + remotedevices_Preknown[i].getBluetoothAddress() );
- }
- }
- hb.getChildren().add(listViewdisck);
- try {
- discoveryAgent.startInquiry(DiscoveryAgent.GIAC, this);
- } catch (BluetoothStateException e) {
- System.out.println("errors 0x11"+e.getMessage());
- }
- stage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- @Override
- public void deviceDiscovered(RemoteDevice rd, DeviceClass dc) {
- try {
- nmdisc.add("Livre: " + rd.getFriendlyName(true));
- } catch (IOException ex) {
- System.out.println(ex.getMessage());
- }
- }
- @Override
- public void servicesDiscovered(int i, ServiceRecord[] srs) {
- }
- @Override
- public void serviceSearchCompleted(int i, int i1) {
- }
- @Override
- public void inquiryCompleted(int i) {
- System.out.println("finalizado "+i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment