NOTE: Only two are implemented - Carpool and Recycle
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MouseClickImgmap extends JApplet implements MouseListener
{
Image img;
ImageIcon icon;
JLabel map, title;
JLabel details;
JPanel center = new JPanel( );
public void init( )
{
setLayout( new BorderLayout( ) );
setupTitle( );
setupMap( );
}
public void setupTitle( )
{
title = new JLabel( "Pollution Solutions", JLabel.CENTER);
title.setFont( new Font( "Serif", Font.BOLD, 26 ) );
title.setForeground( Color.WHITE );
title.setOpaque( true );
title.setBackground( Color.BLACK );
add( title, BorderLayout.NORTH );
details = new JLabel(
"<HTML><CENTER>Click on a bubble above<BR> to get more info!<BR>",
JLabel.CENTER );
details.setForeground( Color.WHITE );
details.setBackground( Color.BLACK );
details.setOpaque( true );
add( details, BorderLayout.SOUTH );
}
public void setupMap( )
{
img = getImage( getCodeBase( ), "PollutionMapSm.jpg" );
icon = new ImageIcon( img );
map = new JLabel( icon );
map.addMouseListener(this);
center.setBackground( Color.BLACK );
center.add(map);
add( center, BorderLayout.CENTER );
}
public void mouseEntered( MouseEvent me ) { }
public void mouseExited( MouseEvent me ) { }
public void mousePressed( MouseEvent me ) { }
public void mouseReleased( MouseEvent me ) { }
public void mouseClicked( MouseEvent me )
{
int x = me.getX( );
int y = me.getY( );
if ( x > 65 && x < 145 && y > 135 && y < 185) // Carpool or bike
{
details.setText("<HTML><CENTER>Carpooling is an excellent way to save the air and your wallet!"
+"<BR>Get together with a group of friends and share a ride."
+"<BR>Or hop on a bike!<BR>Great exercise and no pollution!");
}
else if ( x > 135 && x < 225 && y > 222 && y < 276) // Recycle
{
details.setText("<HTML><CENTER>RECYCLE!"
+"<BR>Everybody's doing it."
+"<BR>So should YOU!<BR>Check your local garbage collection"
+ " to determine what items can be recycled." );
}
}
}