0

I, basically, want to make an image a 'map'. Kind of like google maps, but with my own image. Here are a few of the issues I run into:

1.) Image is too large to fit into applet screen (Solution: click and drag to pan?)

2.) I have no clue how to make it so I can zoom in and out.

3.) I'd like to make it so when a person 'hovers' their mouse over a location, a text box shows up telling them about the area, but disappears when not 'hovering'

Here is my current code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;

public class MapRender extends JApplet {

    BufferedImage img;

    public void paint(Graphics g) {
        g.drawImage(img, 0, 0, null);
    }

    public MapRender() {
       try {
           img = ImageIO.read(new File("Mapv1Resize.PNG"));
       } catch (IOException e) {
       }
    }

    public Dimension getPreferredSize() {
        if (img == null) {
             return new Dimension(100,100);
        } else {
           return new Dimension(img.getWidth(null), img.getHeight(null));
       }
    }

    public static void main(String[] args) {

        JFrame f = new JFrame("Load Image Sample");

        f.addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
                }
            });

        f.add(new MapRender());
        f.pack();
        f.setVisible(true);
    }
}

This code is part of a sample provided by another area, I just changed it to an applet.

Note: I understand whoever helps me can't run the program without the picture, but you can substitute any 2k*2k resolution picture for this.

smttsp
  • 4,011
  • 3
  • 33
  • 62

0 Answers0