コード例 #1
0
 /** @throws IOException error */
 public final void loadImage() throws IOException {
   BufferedImage img;
   try {
     Stage stage = (Stage) Main.getWindow();
     FileChooser fileChooser = new FileChooser();
     fileChooser.setTitle("Open Image File");
     FileChooser.ExtensionFilter extFilterJPG =
         new FileChooser.ExtensionFilter("JPG files (*.jpg)", "*.JPG");
     FileChooser.ExtensionFilter extFilterPNG =
         new FileChooser.ExtensionFilter("PNG files (*.png)", "*.PNG");
     fileChooser.getExtensionFilters().addAll(extFilterJPG, extFilterPNG);
     File f = fileChooser.showOpenDialog(stage);
     if (f != null) {
       logger.info(f.getName());
       img = ImageIO.read(f);
       contactImage = new ContactImage(img);
       if ((contactImage.getHeight() >= 300 || contactImage.getHeight() <= 1000)
           && (contactImage.getWidth() >= 300 || contactImage.getWidth() <= 1000)) {
         contactImage.set(img);
         Image temp = SwingFXUtils.toFXImage(img, null);
         image.setImage(temp);
       } else {
         throw new ImageNotValidException("Foto ist zu groß!");
       }
     }
   } catch (Exception e) {
     logger.log(Level.SEVERE, "Error: " + e.getMessage());
   }
 }
コード例 #2
0
  /** Back to main menu. */
  public final void onBtnBackClick() {

    try {
      Parent root = FXMLLoader.load(getClass().getResource("/view/Main.fxml"));
      Scene scene = new Scene(root);
      Main.getWindow().setScene(scene);
    } catch (IOException e) {
      logger.log(Level.SEVERE, "Couldn't change scene as expected: " + e.getMessage());
    }
  }