int x,y,width,height,imageX,imageY,fontX,fontY; PRivate Image NormalImage, EnterImage,PressImage,DisableImage; private String text; private Font font = new Font("Dialog",Font.PLAIN,12); private Color basicColor = Color.lightGray; private java.lang.Thread draw; private boolean imageLoaded;
private int h_bosomSpace=1,v_bosomSpace=1; private int h_sideSpace=3,v_sideSpace=3;
private int Status = 5; private final static int Normal=1; private final static int Enter=2; private final static int Press=3; private final static int Disable=4; private final static int Hide = 5;
private int Alignment; public final static int HORIZON = 1; //图象和字体左右分布 public final static int VERTICAL = 2; //图象和字体上下分布
public class Tooltips extends Canvas implements java.lang.Runnable {
/* keep是工具提示留屏时间变量 delay是线程空运行时间变量, 到期线程将被暂停 h_sideSpace和v_sideSpace 是左右两侧和上下两侧的空白区域 Status变量记录线程所处的五种状态,初始值为消失 */ private Font font; private int x,y,width,height,fontX,fontY; private int h_sideSpace=3, v_sideSpace=3,keep=3,delay=10; private java.lang.Thread draw; private String text;
private int Status = 4; private final static int Draw = 1; //显示工具提示 private final static int stopDraw = 2; //停止工具提示并清除 private final static int Clear = 3; //清除工具提示 private final static int Hide = 4; //隐藏工具提示 private final static int Suspend = 5; //暂停线程
public Tooltips() { this(new Font("Dialog",Font.PLAIN,12)); } public Tooltips(Font font) { this.font = font; } //提示显示,假如窗体区域不能满足要求,就不会显示 public synchronized void setVisible (String text,Point mouse,Rectangle frame) { if(text==null) return; this.text = text; FontMetrics fm = getFontMetrics(font); int fontWidth = fm.stringWidth(this.text); int fontHeight = fm.getHeight();
public class Multi extends Frame implements ActionListener,MouseListener{ Button butExit = new Button(); ImageButton cmdExit = new ImageButton (ImageCode.mbox,ImageCode.bomb, ImageCode.sound1,ImageCode.mbox, " 千 古 江 山",ImageButton.HORIZON); ImageButton cmdStop = new ImageButton(ImageCode.sound2); ImageButton cmdInfor = new ImageButton(ImageCode.cowSmall); Tooltips tooltips = new Tooltips(new Font("Dialog",Font.PLAIN,14));