Add an Image Filter and Resize the Image

An image file filter

One way to make the program easier to use, and to avoid errors when opening a file, would be to make the file chooser show only image files.

Creating an image file filter

Create a file filter that allows only “.jpg”, “.png”, and “.gif” files. All file filters need a string description of the types of files allowed.

  1. Create a new class in the slidingtiles package called ImageFileFilter, with superclass FileFilter and with no stub code.
  2. Add a public method called getDescription(). It should take no parameters and return a string. getDescription() should return “All image files: *.jpg, *.png, *.gif”.
package slidingtiles;
 
import java.io.File;
import javax.swing.filechooser.FileFilter;
 
public class ImageFileFilter extends FileFilter {
 
  ________________ getDescription(_______) {
    return ________________________;
  }
}

Get hands-on with 1200+ tech skills courses.