home *** CD-ROM | disk | FTP | other *** search
/ Internet 1996 World Exposition / park.org.s3.amazonaws.com.7z / park.org.s3.amazonaws.com / Japan / Fujitsu- / GJ / i / java / navIcon.java
Encoding:
Text File  |  2017-09-21  |  2.6 KB  |  104 lines

  1. // applet takes a graphic, writes some text below the graphic on a mouse over of the 
  2. // graphic and writes the URL that the graphic maps to on the status bar.  On mouse up
  3. // takes user to URL
  4.  
  5.  
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.awt.Event;
  9. import java.applet.*;
  10. import java.awt.*;
  11. import java.net.*;
  12. import java.util.*;
  13.  
  14. public class navIcon extends java.applet.Applet {
  15.  
  16.     Image icon, bakg, txt, currentimg, offscreenImg;
  17.     int currentxpos, xmin, xmax, ymin, ymax, xposimage, xpostxt; 
  18.     Graphics offscreenG;
  19.     URL myURL;
  20.     String strURL = null;
  21.     String strTarget = null;
  22.     
  23.     public void init() {
  24.         String imagename = getParameter("image"); // get image name
  25.         String txtname = getParameter("txt");      // get txt image name
  26.         String bakgname = getParameter("bakg");  // get bakg image name
  27.         strURL = getParameter("URL");      // get destination URL
  28.         strTarget = getParameter("target"); // get frame target
  29.         
  30.         try {
  31.                 myURL = new URL(getDocumentBase(), strURL);    // see if dest URL is legal
  32.         } 
  33.         catch (MalformedURLException e) { 
  34.             System.out.println("Bad URL: " +strURL);
  35.         }
  36.  
  37.         System.out.println("Version 8c");
  38.         System.out.println(strURL + " target: " + strTarget);
  39.  
  40.         icon = getImage(getCodeBase(), "images/"+imagename+".gif");
  41.         bakg = getImage(getCodeBase(), "images/"+bakgname+".gif");
  42.         txt = getImage(getCodeBase(), "images/"+txtname+".gif");
  43.         
  44.         // set initial conditions
  45.         currentimg = bakg;
  46.         currentxpos = 0;
  47.         
  48.         offscreenImg = createImage(this.size().width,this.size().height);
  49.         offscreenG = offscreenImg.getGraphics();
  50.         
  51.         xmin = Integer.parseInt( getParameter("xmin") );
  52.         xmax = Integer.parseInt( getParameter("xmax") );
  53.         ymin = Integer.parseInt( getParameter("ymin") );
  54.         ymax = Integer.parseInt( getParameter("ymax") );
  55.         
  56.         xposimage = Integer.parseInt( getParameter("xposimage") );
  57.         xpostxt = Integer.parseInt( getParameter("xpostxt") );
  58.  
  59.     }
  60.  
  61.     public void paint(Graphics g) {
  62.         offscreenG.drawImage(icon,xposimage,0,this);
  63.  
  64.         offscreenG.drawImage(currentimg,currentxpos,26,this);
  65.         g.drawImage(offscreenImg,0,0,this);
  66.     }
  67.     
  68.     public void update(Graphics g) {
  69.         paint(g);
  70.     }
  71.     
  72.             
  73.     public boolean mouseMove(Event evt, int x, int y) {
  74.  
  75.         this.getAppletContext().showStatus(strURL);
  76.  
  77.         if (x > xmin && x < xmax && y > ymin && y < ymax) {
  78.             currentimg = txt;
  79.             currentxpos = xpostxt;
  80.             repaint();
  81.         } else {
  82.             currentimg = bakg;
  83.             currentxpos = 0;
  84.             repaint();
  85.         }
  86.  
  87.         return true;
  88.     }
  89.     
  90.     public boolean mouseUp(Event evt, int x, int y) {
  91.         if( strTarget == null ) {
  92.             this.getAppletContext().showDocument( myURL );
  93.         }
  94.         else {
  95.             this.getAppletContext().showDocument( myURL, strTarget );
  96. System.out.println("to target");
  97.         }
  98.         return true;
  99.     }
  100.  
  101.  
  102.  
  103. }    
  104.