Java progam using NetBeans - I\'m having problems with my code can anyone help m
ID: 672200 • Letter: J
Question
Java progam using NetBeans - I'm having problems with my code can anyone help me. Objective is to have a photo album that allows you to add pics and deleate pics, then allows you to add data to pics (date, place, and title). This is my code and I have comments on the error lines, thanks
package photoalbum;
import com.sun.scenario.effect.ImageData;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import java.util.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
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 PhotoAlbum 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 = "src/image/";
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();
}
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 (slower)
// 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);
}
public class Album extends Observable {
ArrayList<ImageData> imageData = new ArrayList<>();
ObservableList<ImageData> observableList = FXCollections.observableList(imageData);
public ObservableList<ImageData> getObsList() {
return observableList;
}
private BooleanProperty changed = new SimpleBooleanProperty();
public final boolean getChanged() {
return changed.get();
}
public final void setChanged(boolean value) {
changed.set(value);
}
public BooleanProperty changedProperty() {
return changed;
}
public Album() {
}
List<ImageData> getImageData() {
return imageData;
}
public void addImage(String image, String title, String desc, String loc) { //this really should be a button but not sure how to impiment that
imageData.add(0, ImageData (image, title, desc, loc)); //ImageData showing error in ()'s
}
public void removeImage(ImageView img) {
List<ImageData> toRemove = new ArrayList<>();
for (ImageData a : imageData) {
if (a.getImageView() == img) { //getImageView in error
toRemove.add(a);
observableList.remove(a);
break;
}
}
imageData.removeAll(toRemove);
if (this.getChanged() == true) {
this.setChanged(false);
} else {
this.setChanged(true);
}
}
public void sortAlbumTitle(Album album) { //this really should be a button but not sure how to impiment that
System.out.println("Sort by Title");
Collections.sort(album.getImageData(), (ImageData img1, ImageData img2) -> img1.getTitle().compareToIgnoreCase(img2.getTitle())); //getTitle in error
}
public void sortAlbumDate(Album album) { //this really should be a button but not sure how to impiment that
System.out.println("Sort by Date");
Collections.sort(album.getImageData(), (ImageData img1, ImageData img2) -> img1.getDate().compareTo(img2.getDate())); //getDate in error
}
public void sortAlbumLoc(Album album) { //this really should be a button but not sure how to impiment that
System.out.println("Sort by description");
Collections.sort(album.getImageData(), (ImageData img1, ImageData img2) -> img1.getLocation().compareToIgnoreCase(img2.getLocation())); //getLocation in error
}
}
}
Explanation / Answer
* To change this template, choose Tools | Templates * and open the template in the editor. */ package helloworldapp; /** * * @author */ public class HelloWorldApp { /** * @param args the command line arguments */ public static void main(String[] args) { System.out.println("Hello World!"); } }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.