/** * Gets the IconBox for the specified image IRI. * * @param iri The IRI pointing to the image. * @return The icon box containing the image. * @throws MalformedURLException */ private IconBox getImageBox(IRI iri) throws MalformedURLException { ImageIcon imageIcon = new ImageIcon(iri.toURI().toURL()); imageIcon.getImageLoadStatus(); IconBox iconBox = new IconBox(imageIcon, new HTTPLink(iri.toURI())); iconBox.setMaxHeight(50); return iconBox; }
/** Loads the image. */ public static void loadImage() { if (fileImage != null) return; // already loaded this AppLib.printDebug("Loading introduction image"); ImageIcon fi = AppLib.loadClassImage("images/title.png"); // wait for it... while (fi.getImageLoadStatus() == MediaTracker.LOADING) AppLib.sleep(20L); // load me! fileImage = fi.getImage(); screenImage = screenShot(AppLib.winInfo.getScreenSize()); }
// get an image from the given filename private static Image getImage(String filename) { // to read from file ImageIcon icon = new ImageIcon(filename); // try to read from URL if ((icon == null) || (icon.getImageLoadStatus() != MediaTracker.COMPLETE)) { try { URL url = new URL(filename); icon = new ImageIcon(url); } catch (Exception e) { /* not a url */ } } // in case file is inside a .jar if ((icon == null) || (icon.getImageLoadStatus() != MediaTracker.COMPLETE)) { URL url = StdDraw.class.getResource(filename); if (url == null) throw new RuntimeException("image " + filename + " not found"); icon = new ImageIcon(url); } return icon.getImage(); }
protected void initializeIcon() { icons[0] = new ImageIcon("icons/medicine.png"); icons[1] = new ImageIcon("icons/wine.png"); icons[2] = new ImageIcon("icons/fertilizer.png"); icons[3] = new ImageIcon("icons/iron.png"); icons[4] = new ImageIcon("icons/pigiron.png"); icons[5] = new ImageIcon("icons/steel.png"); icons[6] = new ImageIcon("icons/tools.png"); for (ImageIcon x : icons) { if (x.getImageLoadStatus() == MediaTracker.ERRORED) { System.out.println(x + "failed"); } } firmIcon = new ImageIcon("icons/firm.png"); }