IBM

GIF display applet

This example is an applet which displays an image, typically a GIF file, scaled to fit the size of the applet window.

Here's the source, as a plain ASCII file.

The applet requests an image (specified by its name, relative to the document from which the applet is invoked). It then uses the Java MediaTracker to wait until it has completely arrived. The image is then displayed. The only parameter is the name of the image.

The applet is compiled using the same steps as for the 'Hello World' applet. To have the applet displayed in World Wide Web page, you need to

  1. place the class file in the same directory as the page in which is is to appear
  2. place the image (GIF) file in the same directory as the page in which is is to appear
  3. refer to it, wherever you want it to appear on the page, with the <applet> tag:
      <applet code="GifShow.class" width=200 height=150>
      <param name=gif value="netrexx.gif">
      </applet>
    

    which sets the maximum size for the window in which the applet will appear, and the name of the image.

  4. If the applet was compiled without options binary, you'd also need to place a copy of the NetRexx class files (e.g., from NetRexxR.zip) in a subdirectory netrexx/lang relative to the directory that holds the GifShow.class file. You don't need to do this if you are viewing the applet on a machine where NetRexx has been installed.

You can then view the page with any Java-enabled browser, or with the 'applet viewer' that comes with the Java Development Kit. If you are using such program, you should see the applet below here.

For more details on running applets, see the Hello World applet page.


[ NetRexx | IBM home page | Search | Contact IBM | Help | Legal ]

This page was created on 3 Aug 1997; it can be found from http://www2.hursley.ibm.com/netrexx/