Guest User

bluetoothjfx8

a guest
Dec 8th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.19 KB | None | 0 0
  1. /*
  2.  * bem10jfx.blogspot.com
  3.  * knbjfx.blogspot.com
  4.  *numagrandeviagem.blogspot.com
  5.  */
  6. package bluetwo_fx;
  7.  
  8. import java.io.IOException;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11. import javafx.application.Application;
  12. import javafx.collections.FXCollections;
  13. import javafx.collections.ObservableList;
  14. import javafx.scene.Group;
  15. import javafx.scene.Scene;
  16. import javafx.scene.control.ListView;
  17. import javafx.scene.control.TextArea;
  18. import javafx.scene.layout.HBox;
  19. import javafx.scene.paint.Color;
  20. import javafx.stage.Stage;
  21. import javax.bluetooth.BluetoothStateException;
  22. import javax.bluetooth.DeviceClass;
  23. import javax.bluetooth.DiscoveryAgent;
  24. import javax.bluetooth.DiscoveryListener;
  25. import javax.bluetooth.LocalDevice;
  26. import javax.bluetooth.RemoteDevice;
  27. import javax.bluetooth.ServiceRecord;
  28.  
  29. /**
  30.  *
  31.  * @author kml knb ' s
  32.  */
  33. public class NewClass extends Application implements  DiscoveryListener{
  34.   ObservableList<String> nmpreknown = FXCollections.observableArrayList(  "Preknown");
  35.   ListView<String> listViewpreknown = new ListView<String>(nmpreknown);
  36.  
  37.    ObservableList<String> nmdisc = FXCollections.observableArrayList(  "Ativos não pareados");
  38.   ListView<String> listViewdisck = new ListView<String>(nmdisc);
  39.  
  40.     ObservableList<String> names = FXCollections.observableArrayList(  "cached");
  41.              ListView<String> listView = new ListView<String>(names);
  42.            
  43.     @Override
  44.     public void start(Stage stage) throws IOException  {
  45.         stage.setTitle("Blues");
  46.         Group gp=new Group();
  47.         Scene scene=new Scene(gp,800,400,Color.SILVER);
  48.         stage.setScene(scene);
  49.         HBox hb=new HBox(03);
  50.        gp.getChildren().add(hb);
  51.        
  52.     //adcionar clausula twmorows
  53.         LocalDevice localDevice = null;{try {
  54.          localDevice=LocalDevice.getLocalDevice();
  55.         } catch (BluetoothStateException ex) {
  56.             Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
  57.         }
  58.        }
  59.      DiscoveryAgent  discoveryAgent;
  60.      discoveryAgent = localDevice.getDiscoveryAgent();
  61.  
  62.        //remote device
  63.         RemoteDevice remotedevices[];
  64.          RemoteDevice remotedevices_Preknown[];
  65.         remotedevices = discoveryAgent.retrieveDevices(DiscoveryAgent.CACHED);
  66.              
  67.              hb.getChildren().add(listView);
  68.             if (remotedevices != null) {
  69.                  for (int i=0; i < remotedevices.length; i++) {
  70.                      names.add("Dispositivos no Cached: " +
  71.                             remotedevices[i].getFriendlyName(false) +
  72.                             "-id-" +remotedevices[i].getBluetoothAddress() );
  73.                 }
  74.             }
  75.  
  76.             //--------------------------------
  77.            
  78.                remotedevices_Preknown= discoveryAgent.retrieveDevices(DiscoveryAgent.PREKNOWN);
  79.                hb.getChildren().add(listViewpreknown);
  80.            
  81.             if (remotedevices_Preknown != null) {
  82.                 for (int i=0; i < remotedevices.length; i++) {
  83.                      nmpreknown.add("disp.Pareados: " +
  84.                             remotedevices_Preknown[i].getFriendlyName(false) +
  85.                             " id " + remotedevices_Preknown[i].getBluetoothAddress() );
  86.                  }
  87.             }
  88.    
  89.              hb.getChildren().add(listViewdisck);
  90.              try {
  91.             discoveryAgent.startInquiry(DiscoveryAgent.GIAC, this);
  92.          } catch (BluetoothStateException e) {
  93.             System.out.println("errors 0x11"+e.getMessage());
  94.         }
  95.    
  96.     stage.show();
  97.     }
  98.    
  99.     public static void main(String[] args) {
  100.         launch(args);
  101.     }
  102.  
  103.     @Override
  104.     public void deviceDiscovered(RemoteDevice rd, DeviceClass dc) {
  105.       try {
  106.           nmdisc.add("Livre: " + rd.getFriendlyName(true));
  107.       } catch (IOException ex) {
  108.           System.out.println(ex.getMessage());
  109.       }
  110. }
  111.  
  112.     @Override
  113.     public void servicesDiscovered(int i, ServiceRecord[] srs) {
  114.    }
  115.  
  116.     @Override
  117.     public void serviceSearchCompleted(int i, int i1) {
  118.      
  119.    }
  120.  
  121.     @Override
  122.     public void inquiryCompleted(int i) {
  123. System.out.println("finalizado "+i);
  124.  
  125.     }
  126.    
  127. }
Advertisement
Add Comment
Please, Sign In to add comment