Example usage for java.awt MediaTracker MediaTracker

List of usage examples for java.awt MediaTracker MediaTracker

Introduction

In this page you can find the example usage for java.awt MediaTracker MediaTracker.

Prototype

public MediaTracker(Component comp) 

Source Link

Document

Creates a media tracker to track images for a given component.

Usage

From source file:ColorConvertDemo.java

public void loadImage() {
    displayImage = Toolkit.getDefaultToolkit().getImage("largeJava2sLogo.jpg");
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(displayImage, 1);//w ww.  j a  v  a2s. c om
    try {
        mt.waitForAll();
    } catch (Exception e) {
        System.out.println("Exception while loading.");
    }
    if (displayImage.getWidth(this) == -1) {
        System.out.println("No jpg ");
        System.exit(0);
    }
}

From source file:ImageView.java

public void loadImage() {

    URL url = getClass().getResource(fileName);
    im = Toolkit.getDefaultToolkit().getImage(url);

    // ----- This part omitted from course notes for brevity -----
    // Use a MediaTracker to show the "best"? way of waiting
    // for an image to load, and how to check for errors.
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(im, 0);/*from  w  w  w  . j a v  a 2 s . c o m*/
    try {
        mt.waitForID(0);
    } catch (InterruptedException e) {
        System.err.println("Unexpected interrupt in waitForID!");
        return;
    }
    if (mt.isErrorID(0)) {
        System.err.println("Couldn't load image file " + fileName);
        return;
    }

    // Now that we know the image has been loaded,
    // it is safe to take its width and height.
    // ----- End of part omitted from course notes for brevity -----
    width = im.getWidth(this);
    height = im.getHeight(this);
    setSize(width, height);
}

From source file:ImageOps.java

public void init() {
    setBackground(Color.white);//from  ww w .  j a v a2  s .  com

    bi = new BufferedImage[4];
    String s[] = { "bld.jpg", "bld.jpg", "boat.gif", "boat.gif" };
    for (int i = 0; i < bi.length; i++) {
        Image img = getImage(getURL("images/" + s[i]));
        try {
            MediaTracker tracker = new MediaTracker(this);
            tracker.addImage(img, 0);
            tracker.waitForID(0);
        } catch (Exception e) {
        }
        int iw = img.getWidth(this);
        int ih = img.getHeight(this);
        bi[i] = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
        Graphics2D big = bi[i].createGraphics();
        big.drawImage(img, 0, 0, this);
    }
}

From source file:business.ImageManager.java

/**
 * to be used to draw rastros. don't need cenario.
 *///from w  ww  .  j  av a 2s  . c  o m
private ImageManager() {
    doLoadIconsAll();
    this.form = new JPanel();
    this.mt = new MediaTracker(this.form);
    this.cenario = null;
    doLoadTerrainImages();
    waitForAll();
}

From source file:ConvolveApp.java

public void loadImage() {
    displayImage = Toolkit.getDefaultToolkit().getImage("largeJava2sLogo.jpg");
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(displayImage, 1);//from  ww w.j a  va2 s . c  o m
    try {
        mt.waitForAll();
    } catch (Exception e) {
        System.out.println("Exception while loading.");
    }
    if (displayImage.getWidth(this) == -1) {
        System.out.println("No jpg file");
        System.exit(0);
    }
}

From source file:SimpleBufferedImageDemo.java

DisplayCanvas() {
    displayImage = Toolkit.getDefaultToolkit().getImage("largeJava2sLogo.jpg");

    MediaTracker mt = new MediaTracker(this);
    mt.addImage(displayImage, 1);/*from w w  w  . ja  v  a  2 s  .c  o m*/
    try {
        mt.waitForAll();
    } catch (Exception e) {
        System.out.println("Exception while loading.");
    }

    if (displayImage.getWidth(this) == -1) {
        System.out.println("No *.jpg file");
        System.exit(0);
    }
    setBackground(Color.white);
    setSize(400, 225);
}

From source file:ClipImage.java

public void init() {
    setBackground(Color.white);//from www  .j a v a 2 s. c  o  m
    img = getImage(getURL("images/clouds.jpg"));
    try {
        MediaTracker tracker = new MediaTracker(this);
        tracker.addImage(img, 0);
        tracker.waitForID(0);
    } catch (Exception e) {
    }
}

From source file:business.ImageManager.java

/**
 * use to load images/*from w  ww .  ja va 2s. c  om*/
 *
 * @param form
 * @param aCenario
 */
public ImageManager(JPanel form, Cenario aCenario) {
    doLoadIconsAll();
    this.form = form;
    this.mt = new MediaTracker(form);
    this.cenario = aCenario;
}

From source file:AttributesApp.java

public void loadImage() {
    image = Toolkit.getDefaultToolkit().getImage("largeJava2sLogo.gif");
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 1);//from  w  ww .j  ava  2 s.co m
    try {
        mt.waitForAll();
    } catch (Exception e) {
        System.out.println("Exception while loading.");
    }

    if (image.getWidth(this) == -1) {
        System.out.println("no images");
        System.exit(0);
    }
}

From source file:de.betterform.agent.betty.Betty.java

public void paint(Graphics g) {
    tr = new MediaTracker(this);
    img = getImage(getCodeBase(), "../resources/images/betterform_icon16x16.png");
    tr.addImage(img, 0);/*from   w w  w  .ja v a 2s .c  om*/
    g.drawImage(img, 0, 0, this);
}