import java.applet.Applet; import java.util.Enumeration; import java.awt.Graphics; import java.awt.Color; import java.awt.Event; public class Reporter extends Applet { /* An applet that writes its name directly into any Displayer applet's window. */ private String name; public void init() { name = this.getParameter("ReporterName"); this.setBackground(Color.white); } public void paint(Graphics graphics) { graphics.setColor(Color.red); graphics.drawString(name, 0, 10); } public boolean mouseEnter(Event event, int x, int y) { /* Report something if the user moves over this applet's window. */ Enumeration applets = this.getAppletContext().getApplets(); while (applets.hasMoreElements()) { Applet applet = (Applet) (applets.nextElement()); String itsName = applet.getParameter("DisplayerName"); boolean isOther = (applet != this); boolean isDisplayer = (itsName != null); if (isOther && isDisplayer) { Graphics graphics = applet.getGraphics(); graphics.drawString(name + " calling " + itsName, 0, 40); } } return false; } }