import java.awt.Point; import java.applet.Applet; /** * Klasse zur Berechnung des Offsets eines Applets auf einer HTML-Seite. */ public class AppletPosition { AppletPosition() {}; public static AppletPosition getInstance(Applet appl, String name) { String context = appl.getAppletContext().toString().toLowerCase(); if (context.indexOf("iexplorer") >= 0 || context.startsWith("com.ms.applet")) return new AppletPositionExplorer(appl, name); else return new AppletPosition(); } public Point getPosition() throws Exception { throw new Exception(); } } --- Neue Klasse --- import java.awt.*; import java.applet.*; import netscape.javascript.*; /** * Berechnung des Offset eines Applets in einer HTML-Seite. * Funktioniert nur mit einem InternetExplorer. */ public class AppletPositionExplorer extends AppletPosition { Applet appl; String applName; public AppletPositionExplorer(Applet appl, String applName) { this.appl = appl; this.applName = applName; } public Point getPosition() { Point pos = new Point(0,0); JSObject winObj = JSObject.getWindow( appl); JSObject docObj = (JSObject)winObj.getMember("document"); JSObject appObj = (JSObject)docObj.getMember(applName); pos.y = (int)Double.valueOf(""+appObj.getMember("offsetTop")).doubleValue(); pos.x = (int)Double.valueOf(""+appObj.getMember("offsetLeft")).doubleValue(); return pos; } } --- Neue Klasse --- import java.awt.*; import java.applet.*; public class TransparentApplet extends Applet { Image image = null; AppletPosition pos = null; public void init() { try { // Hintergrundbild über einen MediaTracker laden und Objekt // zur Berechnung der Position des Applets holen. image = getImage(getCodeBase(), getParameter("image")); MediaTracker tracker = new MediaTracker(this); tracker.addImage(image,0); tracker.waitForAll(0); pos = AppletPosition.getInstance(this, getParameter("name")); } catch (Exception e) {} } public void paint(Graphics g) { try { // Position des Applets herausfinden Point off = pos.getPosition(); // Grösse des Bildes lesen int imgWidth = image.getWidth(this); int imgHeight = image.getHeight(this); // Bild gekachelt anzeigen. Offset beachten. for (int x=0-off.x; x Ein transparentes Applet

Transparentes Applet