Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fxmlimageborderpane;
- //import com.sun.deploy.util.SessionState.Client;
- import java.awt.image.BufferedImage;
- import java.io.BufferedReader;
- import java.io.ByteArrayInputStream;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.net.Socket;
- import java.net.URL;
- import java.util.Arrays;
- import java.util.ResourceBundle;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javafx.embed.swing.SwingFXUtils;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.scene.control.Label;
- import javafx.scene.control.Button;
- import javafx.scene.image.Image;
- import javafx.scene.image.ImageView;
- import javax.imageio.ImageIO;
- import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
- public class FXMLDocumentController implements Initializable {
- @FXML
- private Button btnempire;
- @FXML
- private Button btnliberty;
- @FXML
- private Button btncentral;
- @FXML
- private Button btnclear;
- @FXML
- private ImageView imgpic;
- @FXML
- private void handleButtonAction(ActionEvent event) throws IOException {
- Image newImage = null ;
- if (event.getSource() == btncentral) {
- //cerere aici de la client catre server sa primeasca poza -> nu mai folo butonul hard
- //fac un buton "Take Picture"
- //newImage = new Image("file:src/fxmlimageborderpane/images/centpark.jpg");
- Client cl = new Client();
- try {
- Client.sendQuery("QUERY", "SEND_IMAGE", null);
- byte[] imageBytes;
- //Client.waitForResponse(); ->unde se folo?
- imageBytes = cl.waitForFileBytes();
- System.out.println(Arrays.toString(imageBytes));
- BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(imageBytes));
- newImage = SwingFXUtils.toFXImage(bufferedImage, null);
- System.out.println("SUB");
- // imgpic.setImage(newImage);
- } catch (IOException ex) {
- // Logger.getLogger(FXMLMainWindowController.class.getName()).log(Level.SEVERE, null, ex);
- } catch (InterruptedException ex) {
- Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
- }
- } else {
- newImage = null;
- }
- imgpic.setImage(newImage);
- }
- @Override
- public void initialize(URL url, ResourceBundle rb) {
- File file = new File("src/fxmlimageborderpane/images/default.jpg");
- Image image = new Image(file.toURI().toString());
- imgpic.setImage(image);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement