Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Using Java language and specifically JavaFX ONLY no swing or jpanel, netbeans I

ID: 3669597 • Letter: #

Question

(Using Java language and specifically JavaFX ONLY no swing or jpanel, netbeans IDE, REPOST - someone answered the question however the code was incorrect or just flat didnt work when i tried it, plus there was no comments or explinations of what was going on so i was confused on what was wrong.)

My Photos

create a photo album application. Your application will load a collection of images and display them in a photo album layout. The program will allow the user to tag an image with the following metadata:

- Title for the photo (limited to 20 characters)

- Description of the photo. Limited to 100 characters

- Date Taken

- Place Taken

Functional Specification

- Your album should allow sorting the pictures by Title, Date, and Place.

- When the user clicks on a photo, the metadata should be displayed

- The user should be able to add or remove photos from the album

Additional requirements

- Any test photos must be included with project source

- All photos should have maximum and minimum dimensions so that huge photos do not take up all the program’s viewing real estate and smaller photos are not so small that they’re indistinguishable.

- All paths should be relative paths or URL paths. No hard-coded file paths!

- All controls must be viewable without adjusting the parent Window

- Only javaFX GUI controls can be used. No Swing or AWT controls.

- No GUI designers may be used.

I would love this code as a reference, purhaps explain whats going on to me either with comments or seperate, because i know what im doing but only slightly i am a noobie afterall :D. thanks.

Explanation / Answer

Please check below code for reference:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.TilePane;
import javafx.scene.paint.Color;
import javafx.stage.Screen;
import javafx.stage.Stage;

public class ImageProgram extends Application {

Stage stage;

@Override
public void start(Stage primaryStage) throws Exception {
stage = primaryStage;
ScrollPane root = new ScrollPane();
TilePane tile = new TilePane();
root.setStyle("-fx-background-color: DAE6F3;");
tile.setPadding(new Insets(15, 15, 15, 15));
tile.setHgap(15);

String path = "C:/Users/rajdeep.kaur.sidhu/Desktop/Desert/";

File folder = new File(path);
File[] listOfFiles = folder.listFiles();

for (final File file : listOfFiles) {
ImageView imageView;
imageView = createImageView(file);
tile.getChildren().addAll(imageView);
}


root.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); // Horizontal
root.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); // Vertical scroll bar
root.setFitToWidth(true);
root.setContent(tile);

primaryStage.setWidth(Screen.getPrimary().getVisualBounds().getWidth());
primaryStage.setHeight(Screen.getPrimary().getVisualBounds()
.getHeight());
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();

}
  
/* @Override
public void initialize(URL url, ResourceBundle rb) {

String path = "C:/Users/rajdeep.kaur.sidhu/Desktop/Desert/";

File folder = new File(path);
File[] listOfFiles = folder.listFiles();

for (final File file : listOfFiles) {
ImageView imageView;
imageView = createImageView(file);
imagecontainer.getChildren().addAll(imageView);

}

}*/
  
private ImageView createImageView(final File imageFile) {
// DEFAULT_THUMBNAIL_WIDTH is a constant you need to define
// The last two arguments are: preserveRatio, and use smooth resizing

ImageView imageView = null;
try {
final Image image = new Image(new FileInputStream(imageFile), 150, 0, true,
true);
imageView = new ImageView(image);
imageView.setFitWidth(150);
imageView.setOnMouseClicked(new EventHandler<MouseEvent>() {

@Override
public void handle(MouseEvent mouseEvent) {

if(mouseEvent.getButton().equals(MouseButton.PRIMARY)){

if(mouseEvent.getClickCount() == 2){
try {
BorderPane borderPane = new BorderPane();
ImageView imageView = new ImageView();
Image image = new Image(new FileInputStream(imageFile));
imageView.setImage(image);
imageView.setStyle("-fx-background-color: BLACK");
imageView.setFitHeight(stage.getHeight() - 10);
imageView.setPreserveRatio(true);
imageView.setSmooth(true);
imageView.setCache(true);
borderPane.setCenter(imageView);
borderPane.setStyle("-fx-background-color: BLACK");
Stage newStage = new Stage();
newStage.setWidth(stage.getWidth());
newStage.setHeight(stage.getHeight());
newStage.setTitle(imageFile.getName());
Scene scene = new Scene(borderPane,Color.BLACK);
newStage.setScene(scene);
newStage.show();
} catch (FileNotFoundException e) {
e.printStackTrace();
}

}
}
}
});
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
return imageView;
}

public static void main(String[] args) {
launch(args);
}

}