
import java.awt.*;
import java.applet.*;

/**
 *
 * @author  Mark Donnermeyer
 */
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<this.getSize().width; x+=imgWidth) {
                for (int y=0-off.y; y<this.getSize().height; y+=imgHeight) {
                    g.drawImage(image, x, y, this);
                }
            }
        }
        catch (Exception e) {}

        g.setColor(Color.white);
        g.drawString("Ich bin ein Applet", 20, 20);
    }
}
