home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / handson / archive / Issue153 / java / Mirror.java < prev    next >
Encoding:
Java Source  |  1999-04-04  |  1.9 KB  |  69 lines

  1. /*
  2.  * @(#)Mirror.java    1.0 1999/04/03
  3.  * 
  4.  * Copyright (c) 1999, David Griffiths. All Rights Reserved.
  5.  * 
  6.  * This software is the proprietary information of David Griffiths.
  7.  * This source code may not be published or redistributed without the 
  8.  * express permission of the author. 
  9.  * 
  10.  * THE AUTHOR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY 
  11.  * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  12.  * THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  13.  * PURPOSE, OR NON-INFRINGEMENT. THE AUTHOR SHALL NOT BE LIABLE FOR ANY DAMAGES
  14.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  15.  * THIS SOFTWARE OR ITS DERIVATIVES.
  16.  * 
  17.  */
  18.  
  19. import java.awt.Graphics;
  20. import java.awt.Image;
  21. import java.awt.Color;
  22. import java.lang.Math;
  23. import java.awt.*;
  24.  
  25. public class Mirror extends java.applet.Applet {
  26.     Image origImg, backImg;
  27.     int w1, h1;
  28.  
  29.     public void init() {
  30.         loadImage ();
  31.     }
  32.  
  33.     public void loadImage () {
  34.         MediaTracker tracker = new MediaTracker(this);
  35.         String nextImage = getParameter ("image");
  36.         origImg = getImage (getDocumentBase(), nextImage);
  37.  
  38.         tracker.addImage(origImg, 0);
  39.  
  40.         try {
  41.             tracker.waitForID(0);
  42.         }
  43.         catch(InterruptedException e) {}
  44.  
  45.         w1 = origImg.getWidth (this);
  46.         h1 = origImg.getHeight (this);
  47.         backImg = createImage(w1 + 1, h1);
  48.         Graphics backG = backImg.getGraphics();
  49.         backG.drawImage(origImg, 0, 0, this);
  50.         for (int i = 0; i < (w1 >> 1); i++) {
  51.             backG.copyArea(i, 0, 1, h1, w1 - i, 0);
  52.             backG.copyArea(w1 - i, 0, 1, h1, (i << 1) - w1, 0);
  53.             backG.copyArea(w1, 0, 1, h1, - i, 0);
  54.         }
  55.         repaint();
  56.     }
  57.  
  58.     public void update (Graphics g) {
  59.         paint (g);
  60.     }
  61.  
  62.     public void paint (Graphics g) {
  63.         if (origImg != null)
  64.             g.drawImage (origImg, 0, 0, this); 
  65.         if (backImg != null)
  66.             g.drawImage (backImg, w1, 0, this); 
  67.     }
  68. }
  69.