/** * Displays a file chooser for picking a file, loads the picture from the file that the user * selected, and pauses so that the user can see the loaded picture. */ public void pick() { JFileChooser chooser = new JFileChooser("."); chooser.setFileFilter( new FileFilter() { public String getDescription() { return "Image files"; } public boolean accept(File f) { String name = f.getName(); return Arrays.asList(ImageIO.getReaderFileSuffixes()) .contains(name.substring(name.lastIndexOf(".") + 1)); } }); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { load(chooser.getSelectedFile().getAbsolutePath()); draw(); } }
/** * Constructs a picture from a given file or URL. * * @param source the filename or URL */ public Picture(String source) { load(source); }