Guys, I have created a map by making a map panel program and set the images there. I am using the paint component to set the images on the coordinates I want. Now my first problem is solve. The next one is quite hard. The spots on the map has actions. When the mouse is pointed on each of the three spots the cursor will change in to a "pointing hand" then if I right click a pop-up menu will appear. The
pop-up menu only appear if it is pointed on one of the spots, out side the spots will not.
Now my questions are:
1. Is it possible to create an actions, pop-up menu, Tool Tip Text, and Mouse Event coding on the MapPanel.java program?
2. If yes, can I ask for your assistance on how?
3. If not, then the actions, pop-up menu codes, and ect. can done in Landmarks.java. How can I call the objects in MapPanel.java program like the image spot1. Here is the code of my MapPanel.java:
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class MapPanel extends JPanel {
Image map, spot1,spot2,spot3,note;
int height;
public MapPanel() {
super();
Toolkit kit = Toolkit.getDefaultToolkit();
map = kit.getImage("cebumap.jpg");
spot1 = kit.getImage("spot.gif");
spot2 = kit.getImage("spot2.gif");
spot3 = kit.getImage("spot3.gif");
note = kit.getImage("note.gif");
}
public void paintComponent(Graphics comp) {
Graphics2D comp2D = (Graphics2D) comp;
comp2D.drawImage(map,0,0, this);
comp2D.drawImage(spot1,168,30, this);
comp2D.drawImage(spot2,203,255, this);
comp2D.drawImage(spot3,225,205, this);
comp2D.drawImage(note,270,330, this);
}
}
If I want to put an action and tooltiptext on spot1 and the code can be done in Landmarks.java where my JFrame is, how can I call the spot1 on the my Landmarks.java program?
MapPanel mp = new MapPanel();
mp.spot1.setToolTipText("Spot1");
I did it like this but it won't work. Please look at my program. . .