Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

*FROM JAVA SOFTWARE SOLTUIONS 8TH EDITION* In this programming challenge you wil

ID: 3703216 • Letter: #

Question

*FROM JAVA SOFTWARE SOLTUIONS 8TH EDITION*

In this programming challenge you will demonstrate the use of a Scroll Pane.

First study Listing 11.13 on p. 570 of your text.. This program displays a New York Subway Transit Map in a scroll pane. You will modify it in two ways:

1. First you will substitute a satellite image of an area in Kabul, Afganistan in your scroll pane. Notice that the satellite map has an untitled placemark in the center.

2. You want to display a tool tip when you mouse over this placemark. The short line of text that is displayed should read: "Bala Hissar fortress."

3. When the user actually clicks on the placemark an image of the Bala Hissar fortress should pop up on the screen. The images you need are all in the attached folder, including the image of the Bala Hissar fortress.

Code :

}

Explanation / Answer

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TransitMap
{
//MAIN METHOD
   public static void main(String[] args)
   {
   //ImageIcon for Bala_Hissar.jpg
       ImageIcon img1 = new ImageIcon("Bala_Hissar.jpg");
   //FRAME
       JFrame frame = new JFrame("New York Transit Map");
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   //ImageIcon for Bala_Hissar.jpg
       ImageIcon image = new ImageIcon("Fortress.jpg");
       JLabel imageLabel = new JLabel(image);
   //SET TOOL TIP TO THE IMAGE
       JButton tooltipBtn = new JButton(image);
       tooltipBtn.setToolTipText("tooltip");
       imageLabel.setToolTipText("Bala Hissar Forest");
   //ON CLICKING THE IMAGE  
       imageLabel.addMouseListener(new MouseAdapter()
       {
           @Override
           //DISPLAY THE Bala_Hissar.jpg
           public void mouseClicked(MouseEvent mEvent)
           {
               int xx=mEvent.getX();
               int yy=mEvent.getY();
               if(xx > 330 && xx < 440 && yy >200 && yy < 250)
               {
                   imageLabel.setIcon(img1);
               }
           }
       });
       //ScrollPane
       JScrollPane sp = new JScrollPane(imageLabel);
       sp.setPreferredSize(new Dimension(450,400));
       //ADD ScrollPane TO THE FRAME
       frame.getContentPane().add(sp);
       frame.pack();
       frame.setVisible(true);  
   }
}