Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.6 kB
3
Indexable
Never
package cs1302.gallery;

import javafx.scene.layout.VBox;
import javafx.scene.layout.HBox;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.scene.layout.Priority;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;

/**
 * This class creates images for our driver.
 */
public class ImageLoader extends VBox {

    ImageView imgView;

    private static final String DEFAULT_IMG =
        "http://cobweb.cs.uga.edu/~mec/cs1302/gui/default.png";

    private static final int DEF_HEIGHT = 100;
    private static final int DEF_WIDTH = 100;

    /**
     * Creates an image loader object.
     */
    public ImageLoader() {
        super();

        // Load the default image with the default dimensions
        Image img = new Image(DEFAULT_IMG, DEF_HEIGHT, DEF_WIDTH, false, false);

        // Add the image to its container and preserve the aspect ratio
        imgView = new ImageView(img);
        imgView.setPreserveRatio(true);

        // Adds urlLayer and image to the ImageLoader
        this.getChildren().addAll(imgView);
    }

    /**
     * Load images into each image.
     * @param url the url of the desired image.
     */
    public void loadImage(String url) {
        try {
            Image newImg = new Image(url, DEF_HEIGHT, DEF_WIDTH, false, false);
            imgView.setImage(newImg);
        } catch (IllegalArgumentException iae) {
            System.out.println("The supplied URL is invalid");
        }
    }


}