// load the images when the applet begins executing public void init() { int i; this.processHTMLParameters(); if (totalImages == 0 || imageName == null) { this.showStatus("Invalid parameters"); this.destroy(); } images = new Vector(totalImages, 1); imageTracker = new MediaTracker(this); for (i = 0; i < totalImages; i++) { images.addElement(this.getImage(this.getDocumentBase(), "images/" + imageName + i + ".gif")); // track loading image imageTracker.addImage((Image) images.elementAt(i), i); } // wait for the first image, // must use a Joos version of tracker to avoid catching // interruped exception new JoosMediaTracker(imageTracker).waitForID(0); width = ((Image) images.elementAt(0)).getWidth(this); height = ((Image) images.elementAt(0)).getHeight(this); this.resize(width, height + 30); buffer = this.createImage(width, height); gContext = buffer.getGraphics(); // set background of buffer to white gContext.setColor(c.white()); gContext.fillRect(0, 0, 160, 80); this.setLayout(new BorderLayout(10, 10)); sleepLabel = new Label("Sleep time", c.LABEL_CENTER()); sleepDisplay = new TextField("", 5); sleepDisplay.setText(new Integer(sleepTime).toString()); sleepStuff = new Panel(); sleepStuff.add(sleepLabel); sleepStuff.add(sleepDisplay); new JoosContainer(this).addString("South", sleepStuff); }
// start the applet public void start() { // always start with 1st image gContext.drawImage((Image) images.elementAt(0), 0, 0, this); // create a new animation thread when user visits page if (animate == null) { animate = new Thread(new Animator2Run(this, images, imageTracker, gContext)); animate.start(); } }
// display the image in the Applet's Graphics context public void paint(Graphics g) { g.drawImage(buffer, 0, 0, this); }