Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Image Program using Java FX When I just opened a particular image with file chooser, I used the code below. It worked. When I

Java Image Program using Java FX

When I just opened a particular image with file chooser, I used the code below. It worked. When I tried to expand the program to choose a directory and list all the files in it, I figured I could use the same location = (selectedFile.getAbsoluteFile().toURI().toString()); It doesn't work. (Attached my code) What I'm trying to do is choose a directory with file chooser and capture the paths of all the jpg files into an array. I then have to display the images and be able to iterate through them.

What am I doing wrong?

//One image

if(event.getSource()==btnopen){

FileChooser UserImage = new FileChooser(); java.io.File selectedFile = UserImage.showOpenDialog(null); location = (selectedFile.getAbsoluteFile().toURI().toString()); img=new Image(location); FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("Image Files (*.jpg)", "*.jpg"); UserImage.getExtensionFilters().add(extFilter); Object newStage; ************************************************************************************

// Trying to get the files from a directory and store the same path as the individual image.

public void listFiles(String dir){

myList = new ArrayList(); String extension = "jpg";

File directory = new File(dir);

//get all the files from a directory

File[] fList = directory.listFiles();

for (File file : fList){

if (file.isFile()){

if(files.endsWith(extension)) { java.io.File selectedFile = UserImage.showOpenDialog(null); location = (selectedFile.getAbsoluteFile().toURI().toString());

{

// Add files to an arrayList myList.add(files);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions

Question

calculate the percent of common equity for VF company

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago