コード例 #1
0
ファイル: Picture.java プロジェクト: riedlblower/cs-046
  /**
   * 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();
    }
  }
コード例 #2
0
ファイル: Picture.java プロジェクト: riedlblower/cs-046
 /**
  * Constructs a picture from a given file or URL.
  *
  * @param source the filename or URL
  */
 public Picture(String source) {
   load(source);
 }