home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / documentation / tutorial / intl / collation / example / Compatibility.java < prev    next >
Encoding:
Java Source  |  1997-07-13  |  2.1 KB  |  79 lines

  1. /*
  2.  * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for NON-COMMERCIAL purposes and without
  6.  * fee is hereby granted provided that this copyright notice
  7.  * appears in all copies. Please refer to the file "copyright.html"
  8.  * for further important copyright and licensing information.
  9.  *
  10.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  11.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  14.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  15.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  16.  */
  17. import java.applet.*;
  18. import java.awt.*;
  19.  
  20. public class Compatibility extends Applet {
  21.     /* Should localize the following. */
  22.     protected String labelText = "Your browser can't run 1.1 applets.";
  23.     protected String filename;   // value to be provided by a subclass
  24.     PictureFrame frame;
  25.  
  26.     public void init() {
  27.     setLayout(new BorderLayout());
  28.  
  29.     Button button = new Button("What Am I Missing?");
  30.     add("Center", button);
  31.  
  32.     Label label = new Label(labelText);
  33.     label.setForeground(Color.red);
  34.     add("North", label);
  35.  
  36.     if (filename == null) {
  37.         label.disable();
  38.         button.disable();
  39.         return;
  40.     } 
  41.  
  42.     Image image = getImage(getCodeBase(), filename);
  43.     String gifWidth = getParameter("GIFWIDTH");
  44.     String gifHeight = getParameter("GIFHEIGHT");
  45.     int w = 200;
  46.     int h = 200;
  47.  
  48.     if (gifWidth != null) {
  49.         try {
  50.         w = Integer.parseInt(gifWidth);
  51.         } catch (NumberFormatException e) {
  52.         //Use default width.
  53.         }
  54.     }
  55.  
  56.     if (gifHeight != null) {
  57.         try {
  58.         h = Integer.parseInt(gifHeight);
  59.         } catch (NumberFormatException e) {
  60.         //Use default height.
  61.         }
  62.     }
  63.  
  64.     frame = new PictureFrame(image, w, h);
  65.     }
  66.  
  67.     public void stop() {
  68.     frame.hide();
  69.     }
  70.  
  71.     public boolean action(Event e, Object arg) {
  72.     if (frame != null) {
  73.         frame.pack();
  74.         frame.show();
  75.     }
  76.     return true;
  77.     }
  78. }
  79.