📄 imagemap.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ImageMap extends JApplet
{
private ImageIcon imageIcon,imageIcon1,imageIcon2,imageIcon3;
private int width,height,iconNum=4;
public void init()
{
addMouseListener(new MyMouseAdapter());
addMouseMotionListener(new MyMotionAdapter());
imageIcon=new ImageIcon("gif-0004.gif");
imageIcon1=new ImageIcon("gif-0004.gif");
imageIcon2=new ImageIcon("gif-0004.gif");
imageIcon3=new ImageIcon("gif-0004.gif");
width=imageIcon.getIconWidth()*4;
height=imageIcon.getIconHeight();
setSize(width,height);
}
class MyMouseAdapter extends MouseAdapter
{
public void mouseExited(MouseEvent e)
{
showStatus("\t\t鼠标指到图形外面.");
}
}
class MyMotionAdapter extends MouseMotionAdapter
{
public void mouseMoved(MouseEvent e)
{
showStatus("\t\t"+checkWidth(e.getX()));
}
}
public void paint(Graphics g)
{
imageIcon.paintIcon(this,g,0,0);
imageIcon1.paintIcon(this,g,width/4,0);
imageIcon2.paintIcon(this,g,2*width/4,0);
imageIcon3.paintIcon(this,g,3*width/4,0);
}
public String checkWidth(int w)
{
int iconWidth=width/iconNum;
if(w>=0&&w<=iconWidth)
return "左道封闭";
else if(w>iconWidth&&w<=iconWidth*2)
return "停车检查";
else if(w>iconWidth*2&&w<=iconWidth*3)
return "路面高突";
else if(w>iconWidth*3&&w<=iconWidth*4)
return "连续弯路";
return "";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -