import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ImageMap extends JApplet { private ImageIcon mapImage; private int width, height; public void init() { addMouseListener( new MouseAdapter() { public void mouseExited( MouseEvent e ) { showStatus( "Pointer outside applet" ); } } ); addMouseMotionListener( new MouseMotionAdapter() { public void mouseMoved( MouseEvent e ) { showStatus( translateLocation( e.getX() ) ); } } ); mapImage = new ImageIcon( "icons2.gif" ); width = mapImage.getIconWidth(); height = mapImage.getIconHeight(); setSize( width, height ); } public void paint( Graphics g ) { mapImage.paintIcon( this, g, 0, 0 ); } static final String str[] = { "Common Programming Error", "Good Programming Practice", "Performance Tip", "Portability Tip", "Software Engineering Observation","Testing and Debugging Tip" }; public String translateLocation( int x ) { // determine width of each icon (there are 6) int iconWidth = width / 6; int idx = x / iconWidth; return (idx<str.length? str[idx]: ""); } }
Maintained by John Loomis, last updated 19 July 2000