关于用APPLET做地图的,大家一定看看帮忙!
我的问题都是关于制作地图定位的,请大家帮忙:
一,导入一个全国地图,在地图上某地点击鼠标,可以显示该地在全国地图的坐标。我现在可以把这个程序分成两个小程序做:
1导入全国地图,程序如下:
import java.awt.*;
import java.applet.*;
/*
<APPLET
CODE=image.class
WIDTH=500
HEIGHT=500>
</APPLET>
*/
public class image extends Applet{
Image image;
public void init(){
image=getImage(getDocumentBase(),"image.jpg");
}
public void paint(Graphics g)
{
g.drawImage(image,150,150,this);}}
当然这个image.jpg要自己在网上找拉,是个全国地图。
2 在空白页上做出点击鼠标显示坐标的程序,如下:
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
/*
<APPLET
CODE=mouse.class
WIDTH=300
HEIGHT=200>
</APPLET>
*/
public class mouse extends Applet implements MouseListener,
MouseMotionListener
{
TextField text1;
public void init()
{
text1=new TextField(30);
add(text1);
addMouseListener(this);
addMouseMotionListener(this);
}
public void mousePressed(MouseEvent e)
{
if((e.getModifiers()&InputEvent.BUTTON1_MASK)==InputEvent.BUTTON1_MASK){
text1.setText("Left mouse button down at"+e.getX()+","+e.getY());
}
else{
text1.setText("Right mouse button down at"+e.getX()+","+e.getY());
}
}
public void mouseClicked(MouseEvent e)
{
text1.setText("You clicked the mouse at"+e.getX()+","+e.getY());
}
public void mouseReleased(MouseEvent e)
{
text1.setText("The mouse button went up.");
}
public void mouseEntered(MouseEvent e)
{
text1.setText("The mouse entered.");
}
public void mouseExited(MouseEvent e)
{
text1.setText("The mouse exited.");
}
public void mouseDragged(MouseEvent e)
{
text1.setText("The mouse was dragged.");
}
public void mouseMoved(MouseEvent e)
{
text1.setText("The mouse was moved.");
}}
但是我不知道怎样把这两个程序结合 ,做出在地图上用鼠标点击可以显示坐标的程序,请大家帮忙看看!
二,已下载的全国地图上北京二字是已经存在的,我怎样使北京二字变成可点击的呢?并且点击之后可以显示另一张地图,即北京市地图?真心希望大家帮忙解答,谢谢!