// Img - alternative to HTML // // A simple Java applet that acts like an HTML tag. One reason // you might use this instead of is that it's harder for users // to save images being displayed through an applet - a primitive // form of copy-protection. // // Downsides: // - Under most circumstances, it's a lot slower. // - With the current applet security constraints, it can only // load images from the same network site that the Img applet itself // was loaded from. // // Parameters: // SRC - the URL to load // // Copyright (C) 1996 by Jef Poskanzer . All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF // SUCH DAMAGE. import java.applet.*; import java.awt.*; import java.awt.image.*; import java.net.*; public class Img extends Applet implements ImageObserver { // Applet info. public String getAppletInfo() { return getClass().getName() + " - Copyright (C) 1996 by Jef Poskanzer . All rights reserved."; } // Parameter info. public String[][] getParameterInfo() { String[][] info = { { "SRC", "URL", "the image to load" }, }; return info; } // Called when the applet is first created. public void init() { Acme.GuiUtils.handleBgcolor( this ); URL context = getDocumentBase(); String src = getParameter( "SRC" ); try { URL url = new URL( context, src ); Image img; if ( url == null ) img = Acme.GuiUtils.brokenIcon( this ); else img = getImage( url ); add( "Center", new Acme.Widgets.ImageLabel( img ) ); } catch ( Exception e ) { System.err.println( e ); e.printStackTrace(); } } }