144.

previous chapter table of contents next chapter
  

Images

User interfaces often contain images. They may be used as icons in toolbars , as general images on the screen, or as the icon image when the application is iconified . When a user interface is created on the client, these images will also need to be created and installed in the relevant part of the application. Images are not serializable, so they cannot be created on the server and exported as live objects in some manner. They need to be created from scratch on the client.

The Swing package contains a convenience class called ImageIcon . This class can be instantiated from a byte array, a filename, or most interestingly here, from a URL. So, if an image is stored where an HTTP server can find it, the ImageIcon constructor can use this version directly. There may be failures in this approach: the URL may be incorrect or malformed or the image may not exist on the HTTP server. Suitable code to create an image from a URL is as follows :

 ImageIcon icon = null;         try {             icon = new ImageIcon(new URL("http://localhost/images/MINDSTORMS.ps"));             switch (icon.getImageLoadStatus()) {             case MediaTracker.ABORTED:             case MediaTracker.ERRORED:                 System.out.println("Error");                 icon = null;                 break;             case MediaTracker.COMPLETE:                 System.out.println("Complete");                 break;             case MediaTracker.LOADING:                 System.out.println("Loading");                 break;             }         } catch(java.net.MalformedURLException e) {             e.printStackTrace();         }         // icon is null or is a valid image 
  


A Programmer[ap]s Guide to Jini Technology
A Programmer[ap]s Guide to Jini Technology
ISBN: 1893115801
EAN: N/A
Year: 2000
Pages: 189

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net