《Java2图形设计卷II:Swing》配套光盘源码

源代码在线查看: tooltipsbasedonmouseposition.java

软件大小: 4504 K
上传用户: guigong
关键词: Java2 Swing 图形 光盘
下载地址: 免注册下载 普通下载 VIP

相关代码

				import javax.swing.*;
				import java.awt.*;
				import java.awt.event.*;
				
				public class ToolTipsBasedOnMousePosition extends JApplet {
					public void init() {
						Container contentPane = getContentPane();
						ImageMap map = new ImageMap("tiger.gif");
						contentPane.setLayout(new FlowLayout());
						contentPane.add(map);
					}
				}
				class ImageMap extends JLabel {
					private Rectangle 	teeth= new Rectangle(62,203,80,55),
										nose = new Rectangle(37,164,130,30),
										ear	= new Rectangle(228,10,65,55),
										rEye = new Rectangle(137,103,20,17),
										lEye = new Rectangle(65,97,16,15);
				
					public ImageMap(String imageName) {
						super(new ImageIcon(imageName));
						setToolTipText("tiger!");
					}
					public String getToolTipText(MouseEvent e) {
						Point 	p = e.getPoint();
						String	s = null;
				
						if(teeth.contains(p)) 		s = "ooooh, big teeth!";
						else if(nose.contains(p))	s = "keen sense of smell";
						else if(ear.contains(p))	s = "acute hearing";
						else if(rEye.contains(p) || lEye.contains(p)) 
							s = "excellent vision";
				
						return s == null ? getToolTipText() : s;
					}
				}
							

相关资源