还是关于做地图的问题,设计的差不多了,还要请大家改进!
我现在已经做出一个可以在地图上看坐标的程序,可是还是不知道怎么把北京二字变为可点击的,大家继续帮忙!程序如下: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
{
Image image;
TextField text1;
public void init()
{
text1=new TextField(30);
add(text1);
addMouseListener(this);
addMouseMotionListener(this);
image=getImage(getDocumentBase(),"image.jpg"); //参照你的代码增加
}
public void paint(Graphics g)
{
g.drawImage(image,150,150,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.");
}
}
以上是鼠标事件,大家可以保存为Mouse.java
<html>
<head>
<title>MyMap</title>
</head>
<body>
<applet
code="Mouse.class"
width=300
height=300
>
</applet>
</body>
</html>
以上是一个HTML文件,可保存为map.html,
当然大家还要导入一个地图文件,这里不能帖图,http://www.culturalink.gov.cn/chinamap.htm可以去这下一个放在和刚才两个文件保存在同一个文件夹中。
这样在APPLET中就可以运行了,只是不太好看。请大家帮忙做的人性化些,怎样才能把鼠标放在北京二字上就会出现坐标?而不用点击后才出现?我现在要的是点击后出现北京市地图!谢谢大家,一起完成这个程序,好吗?