home *** CD-ROM | disk | FTP | other *** search
- // applet takes a graphic, writes some text below the graphic on a mouse over of the
- // graphic and writes the URL that the graphic maps to on the status bar. On mouse up
- // takes user to URL
-
-
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Event;
- import java.applet.*;
- import java.awt.*;
- import java.net.*;
- import java.util.*;
-
- public class navIcon extends java.applet.Applet {
-
- Image icon, bakg, txt, currentimg, offscreenImg;
- int currentxpos, xmin, xmax, ymin, ymax, xposimage, xpostxt;
- Graphics offscreenG;
- URL myURL;
- String strURL = null;
- String strTarget = null;
-
- public void init() {
- String imagename = getParameter("image"); // get image name
- String txtname = getParameter("txt"); // get txt image name
- String bakgname = getParameter("bakg"); // get bakg image name
- strURL = getParameter("URL"); // get destination URL
- strTarget = getParameter("target"); // get frame target
-
- try {
- myURL = new URL(getDocumentBase(), strURL); // see if dest URL is legal
- }
- catch (MalformedURLException e) {
- System.out.println("Bad URL: " +strURL);
- }
-
- System.out.println("Version 8c");
- System.out.println(strURL + " target: " + strTarget);
-
- icon = getImage(getCodeBase(), "images/"+imagename+".gif");
- bakg = getImage(getCodeBase(), "images/"+bakgname+".gif");
- txt = getImage(getCodeBase(), "images/"+txtname+".gif");
-
- // set initial conditions
- currentimg = bakg;
- currentxpos = 0;
-
- offscreenImg = createImage(this.size().width,this.size().height);
- offscreenG = offscreenImg.getGraphics();
-
- xmin = Integer.parseInt( getParameter("xmin") );
- xmax = Integer.parseInt( getParameter("xmax") );
- ymin = Integer.parseInt( getParameter("ymin") );
- ymax = Integer.parseInt( getParameter("ymax") );
-
- xposimage = Integer.parseInt( getParameter("xposimage") );
- xpostxt = Integer.parseInt( getParameter("xpostxt") );
-
- }
-
- public void paint(Graphics g) {
- offscreenG.drawImage(icon,xposimage,0,this);
-
- offscreenG.drawImage(currentimg,currentxpos,26,this);
- g.drawImage(offscreenImg,0,0,this);
- }
-
- public void update(Graphics g) {
- paint(g);
- }
-
-
- public boolean mouseMove(Event evt, int x, int y) {
-
- this.getAppletContext().showStatus(strURL);
-
- if (x > xmin && x < xmax && y > ymin && y < ymax) {
- currentimg = txt;
- currentxpos = xpostxt;
- repaint();
- } else {
- currentimg = bakg;
- currentxpos = 0;
- repaint();
- }
-
- return true;
- }
-
- public boolean mouseUp(Event evt, int x, int y) {
- if( strTarget == null ) {
- this.getAppletContext().showDocument( myURL );
- }
- else {
- this.getAppletContext().showDocument( myURL, strTarget );
- System.out.println("to target");
- }
- return true;
- }
-
-
-
- }
-