home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1997 April / Win95_04974.iso / docs / 00016 / 01649.exe / data.2 / program / Java / MultiButton.JAVA < prev    next >
Encoding:
Java Source  |  1997-04-08  |  2.5 KB  |  97 lines

  1.  
  2. // MultiButton, generated with the Mortar JavaImageHandler gnome
  3. //
  4. // Parameters
  5. // NAME               DEFAULT/EX VAL. VALUE FORMAT, DESCRIPTION
  6. //------------------- --------------- ----------------------------------------
  7. // backgroundColor    000000          RRGGBB, in base 16 (hexadecimal); 00-FF
  8.     
  9. import java.applet.Applet;
  10. import java.awt.*;
  11. import java.net.*;
  12. import java.util.*;
  13.  
  14. public class MultiButton extends Applet 
  15. {
  16.     public Color backgroundColor, foregroundColor;
  17.     
  18.     public boolean threadSuspended=false;
  19.  
  20.     // Image-related variables
  21.     protected int numImages=0;
  22.     protected MediaTracker tracker;
  23.     protected Image imgNormal, imgHighlight;
  24.  
  25.     public void init()
  26.     {
  27.         // Create the foregroundColor as the complementary to the backgroundColor
  28.         backgroundColor = IEExtend.strColor( getParameter( "backgroundColor" ), Color.black);
  29.         foregroundColor = new Color( 255-backgroundColor.getRed(),
  30.                                 255-backgroundColor.getGreen(),
  31.                                 255-backgroundColor.getBlue() );
  32.         tracker = new MediaTracker( this );
  33.  
  34.          imgNormal = getImage(getDocumentBase(), getParameter("normal"));
  35.          imgHighlight = getImage(getDocumentBase(), getParameter("highlight"));
  36.          
  37. //         tracker.addImage(imgNormal, 0);
  38. //         tracker.addImage(imgHighlight, 1);
  39.          
  40.         repaint();
  41.     }
  42.  
  43.     public void start() 
  44.     {
  45.         loadResultMessage = loadImages();
  46.     }
  47.  
  48.     // Mouse button handling code
  49.     public boolean mouseDown(Event event, int x, int y)
  50.     {
  51.         return true;
  52.    }
  53.  
  54.     // This method handles drawing.
  55.     public void paint(Graphics g)
  56.     {
  57.         Dimension d = this.size();
  58.  
  59.       g.drawImage(imgNormal,0,0,this);
  60.     }
  61.  
  62.     protected String loadResultMessage = "";
  63.     
  64.     public String loadImages()
  65.     {
  66.         this.showStatus( "Loading images..." );
  67.         Thread n = Thread.currentThread();
  68.         try 
  69.         {
  70.             tracker.waitForAll();
  71.         }
  72.         catch (InterruptedException e) 
  73.             {}
  74.          catch(NullPointerException e)
  75.             {}
  76.             
  77.  
  78.         if( tracker.isErrorAny() );
  79.         {
  80.             for( int i=0; i<2; i++ ) 
  81.             {
  82.                 if (tracker.isErrorID(i)) 
  83.                 {
  84.                     String message = "Error loading \"image" + i + "\"" ;
  85.                     this.showStatus( message );
  86.                     return message;
  87.                 }
  88.             }
  89.         }
  90.  
  91.         return ("2 images loaded successfully.");
  92.     }
  93.  
  94. }
  95.  
  96.  
  97.