use of java.awt.MediaTracker in project JWildfire by thargor6.
the class WelcomeInternalFrame method getImage.
private SimpleImage getImage(String pName) throws Exception {
byte[] imgData = getImagedata(pName);
Image fileImg = Toolkit.getDefaultToolkit().createImage(imgData);
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(fileImg, 0);
tracker.waitForID(0);
int width = fileImg.getWidth(null);
int height = fileImg.getHeight(null);
BufferedImage bImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = bImg.getGraphics();
g.drawImage(fileImg, 0, 0, null);
fileImg = null;
return new SimpleImage(bImg, width, height);
}
use of java.awt.MediaTracker in project JSettlers2 by jdmonin.
the class SOCFaceButton method loadImages.
private static synchronized void loadImages(Component c) {
if (images == null) {
tracker = new MediaTracker(c);
Toolkit tk = c.getToolkit();
Class<?> clazz = c.getClass();
images = new Image[NUM_FACES];
robotImages = new Image[NUM_ROBOT_FACES];
/**
* load the images
*/
robotImages[0] = tk.getImage(clazz.getResource(IMAGEDIR + "/robot.gif"));
tracker.addImage(robotImages[0], 0);
for (int i = 1; i < NUM_FACES; i++) {
images[i] = tk.getImage(clazz.getResource(IMAGEDIR + "/face" + i + ".gif"));
tracker.addImage(images[i], 0);
}
for (int i = 1; i < NUM_ROBOT_FACES; i++) {
// Client possibly only has robot.gif.
// Check getResource vs null, and use MediaTracker;
// drawFace can check tracker.statusID vs MediaTracker.COMPLETE.
URL imgSrc = clazz.getResource(IMAGEDIR + "/robot" + i + ".gif");
if (imgSrc != null) {
robotImages[i] = tk.getImage(imgSrc);
tracker.addImage(robotImages[i], i);
}
}
try {
tracker.waitForID(0);
} catch (InterruptedException e) {
}
if (tracker.isErrorID(0)) {
System.out.println("Error loading Face images");
}
}
}
use of java.awt.MediaTracker in project Spark by igniterealtime.
the class GraphicUtils method load.
/**
* Loading an image via a MediaTracker
*
* @param image
* @throws InterruptedException
* @throws IOException
*/
public static void load(Image image) throws InterruptedException, IOException {
// any component
MediaTracker tracker = new MediaTracker(new Label());
// will do
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorID(0))
throw new IOException("error loading image");
}
use of java.awt.MediaTracker in project triplea by triplea-game.
the class GameRunner method getGameIcon.
public static Image getGameIcon(final Window frame) {
Image img = null;
try {
img = frame.getToolkit().getImage(GameRunner.class.getResource("ta_icon.png"));
} catch (final Exception ex) {
ClientLogger.logError("ta_icon.png not loaded", ex);
}
final MediaTracker tracker = new MediaTracker(frame);
tracker.addImage(img, 0);
try {
tracker.waitForAll();
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
}
return img;
}
use of java.awt.MediaTracker in project triplea by triplea-game.
the class ReliefImageBreaker method loadImage.
/**
* Asks the user to select an image and then it loads it up into an Image
* object and returns it to the calling class.
*
* @return The loaded image.
*/
private Image loadImage() {
ToolLogger.info("Select the map");
final String mapName = new FileOpen("Select The Map", mapFolderLocation, ".gif", ".png").getPathString();
if (mapName != null) {
final Image img = Toolkit.getDefaultToolkit().createImage(mapName);
final MediaTracker tracker = new MediaTracker(new Panel());
tracker.addImage(img, 1);
try {
tracker.waitForAll();
return img;
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
}
return null;
}
Aggregations