Advertisement
alexarcan

controller.java

May 26th, 2016
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. package fxmlimageborderpane;
  2.  
  3. //import com.sun.deploy.util.SessionState.Client;
  4. import java.awt.image.BufferedImage;
  5. import java.io.BufferedReader;
  6. import java.io.ByteArrayInputStream;
  7. import java.io.File;
  8. import java.io.IOException;
  9. import java.io.InputStreamReader;
  10. import java.io.PrintWriter;
  11. import java.net.Socket;
  12. import java.net.URL;
  13. import java.util.Arrays;
  14. import java.util.ResourceBundle;
  15. import java.util.logging.Level;
  16. import java.util.logging.Logger;
  17. import javafx.embed.swing.SwingFXUtils;
  18. import javafx.event.ActionEvent;
  19. import javafx.fxml.FXML;
  20. import javafx.fxml.Initializable;
  21. import javafx.scene.control.Label;
  22. import javafx.scene.control.Button;
  23. import javafx.scene.image.Image;
  24. import javafx.scene.image.ImageView;
  25. import javax.imageio.ImageIO;
  26. import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
  27.  
  28. public class FXMLDocumentController implements Initializable {
  29.  
  30. @FXML
  31. private Button btnempire;
  32. @FXML
  33. private Button btnliberty;
  34. @FXML
  35. private Button btncentral;
  36. @FXML
  37. private Button btnclear;
  38. @FXML
  39. private ImageView imgpic;
  40.  
  41. @FXML
  42. private void handleButtonAction(ActionEvent event) throws IOException {
  43. Image newImage = null ;
  44. if (event.getSource() == btncentral) {
  45. //cerere aici de la client catre server sa primeasca poza -> nu mai folo butonul hard
  46. //fac un buton "Take Picture"
  47. //newImage = new Image("file:src/fxmlimageborderpane/images/centpark.jpg");
  48.  
  49. Client cl = new Client();
  50. try {
  51. Client.sendQuery("QUERY", "SEND_IMAGE", null);
  52. byte[] imageBytes;
  53.  
  54. //Client.waitForResponse(); ->unde se folo?
  55. imageBytes = cl.waitForFileBytes();
  56. System.out.println(Arrays.toString(imageBytes));
  57. BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(imageBytes));
  58. newImage = SwingFXUtils.toFXImage(bufferedImage, null);
  59. System.out.println("SUB");
  60. // imgpic.setImage(newImage);
  61. } catch (IOException ex) {
  62. // Logger.getLogger(FXMLMainWindowController.class.getName()).log(Level.SEVERE, null, ex);
  63. } catch (InterruptedException ex) {
  64. Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
  65. }
  66. } else {
  67. newImage = null;
  68. }
  69.  
  70. imgpic.setImage(newImage);
  71.  
  72. }
  73.  
  74. @Override
  75. public void initialize(URL url, ResourceBundle rb) {
  76. File file = new File("src/fxmlimageborderpane/images/default.jpg");
  77. Image image = new Image(file.toURI().toString());
  78. imgpic.setImage(image);
  79.  
  80. }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement