/* File: BubbleTest.java Author: Chris Johnson johnson@dcs.gla.ac.uk Modified: 16/10/98 Acknowledgement: This is based on an Applet developed by D.M. Geary in Graphic Java 1.1, Sunsoft Press, 1997, p.280. His version is based on AWT1.1 - I've adapted it to run under AWT1.0. Description: This class illustrates the use of a Tooltips or balloon help facility. Three panels are created and a help Bubble is displayed as the mouse moves over those panels. Warning: This Applet will run as intended under Semantic Cafe's AppletViewer. It will not behave as intended on all other platforms. The reason for this is that the precise details of event handling in 1.0 differ from platform to platform. Using Netscape on a Mac, no events are passed to the Applet from any screen areas once the Bubble is presented. In other words, if you move the mouse from one panel to another then the MOUSE_EXIT event is not passed to the Applet. There may be a way to avoid this in AWT1.0 but the problem can be avoided in the more advanced event model of AWT 1.1. */ import java.applet.Applet; import java.awt.*; public class BubbleTest extends Applet { public void init() { BubblePanel left = new BubblePanel("left"); BubblePanel middle = new BubblePanel("middle"); BubblePanel right = new BubblePanel("right"); add(left); add(middle); add(right); validate(); } } class BubblePanel extends BorderedPanel { Bubble bubble; String bubbleText; public Dimension preferredSize(){ return new Dimension(80, 80); } public boolean handleEvent (Event e){ BubblePanel canvas= this; Point scrnLoc = canvas.location(); Dimension Component_size = size(); if (e.target instanceof BubblePanel) { if (e.id == Event.MOUSE_ENTER) { if (bubble==null) bubble = new Bubble(canvas, bubbleText); bubble.move(scrnLoc.x, scrnLoc.y = Component_size.height + 2); bubble.show(); return true; } else if (e.id == Event.MOUSE_EXIT) { if (bubble != null && bubble.isShowing()) bubble.dispose(); return true; } } return super.handleEvent(e); } public BubblePanel (String string) { bubbleText = string; } }