Ejemplo n.º 1
0
  /**
   * Method to write the contents of the picture to a file with the passed name
   *
   * @param fileName the name of the file to write the picture to
   */
  public void writeOrFail(String fileName) throws IOException {
    String extension = this.extension; // the default is current

    // create the file object
    File file = new File(fileName);
    File fileLoc = file.getParentFile(); // directory name

    // if there is no parent directory use the current media dir
    if (fileLoc == null) {
      fileName = FileChooser.getMediaPath(fileName);
      file = new File(fileName);
      fileLoc = file.getParentFile();
    }

    // check that you can write to the directory
    if (!fileLoc.canWrite()) {
      throw new IOException(
          fileName + " could not be opened. Check to see if you can write to the directory.");
    }

    // get the extension
    int posDot = fileName.indexOf('.');
    if (posDot >= 0) extension = fileName.substring(posDot + 1);

    // write the contents of the buffered image to the file
    ImageIO.write(bufferedImage, extension, file);
  }
 public static void main(String[] args) {
   Picture p = new Picture(FileChooser.getMediaPath("horse.jpg"));
   Graphics g = p.getGraphics();
   Point ul = new Point(68, 24);
   Point te = new Point(182, 123);
   String message = "This is a test." + "  Of a message with more than one line in it.";
   SpeechBalloon balloon = new SpeechBalloon(ul, 200, te, message);
   balloon.draw(g);
   p.show();
 }
Ejemplo n.º 3
0
 public static void main(String[] args) {
   String fileName = FileChooser.pickAFile();
   Picture pictObj = new Picture(fileName);
   pictObj.changeWhole(.5);
   pictObj.changeWhole(.8);
   pictObj.scrible(200, 200, 50);
   pictObj.scrible(350, 320, 100);
   pictObj.ManipBoxUniformly(200, 200, 300, 300, .2);
   pictObj.ManipBoxUniformly(100, 100, 400, 300, .5);
   pictObj.ManipBoxPattern(100, 100, 300, 300, .3);
   pictObj.ManipBoxPattern(300, 300, 400, 400, .8);
   pictObj.explore();
 }
Ejemplo n.º 4
0
  /**
   * Method to load the picture from the passed file name
   *
   * @param fileName the file name to use to load the picture from
   * @throws IOException if the picture isn't found
   */
  public void loadOrFail(String fileName) throws IOException {
    // set the current picture's file name
    this.fileName = fileName;

    // set the extension
    int posDot = fileName.indexOf('.');
    if (posDot >= 0) this.extension = fileName.substring(posDot + 1);

    // if the current title is null use the file name
    if (title == null) title = fileName;

    File file = new File(this.fileName);

    if (!file.canRead()) {
      // try adding the media path
      file = new File(FileChooser.getMediaPath(this.fileName));
      if (!file.canRead()) {
        throw new IOException(
            this.fileName + " could not be opened. Check that you specified the path");
      }
    }

    bufferedImage = ImageIO.read(file);
  }
Ejemplo n.º 5
0
 /**
  * Method to get the directory for the media
  *
  * @param fileName the base file name to use
  * @return the full path name by appending the file name to the media directory
  */
 public static String getMediaPath(String fileName) {
   return FileChooser.getMediaPath(fileName);
 }