[3666] in java-interest

home help back first fref pref prev next nref lref last post

Re: Simple Draw Image

daemon@ATHENA.MIT.EDU (Jill Shermer)
Tue Nov 21 21:06:05 1995

Date: Tue, 21 Nov 1995 15:02:03 -0800
From: jshermer@BASISinc.com (Jill Shermer)
To: flar@bendenweyr.Eng.Sun.COM
Cc: java-interest@java.sun.com

----------
X-Sun-Data-Type: text
X-Sun-Data-Description: text
X-Sun-Data-Name: text
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 43

HI,

See my attached file which uses the regular method
 drawImage(img, width, height, this).

Thanks,

-Jill

----- Begin Included Message -----

From flar@bendenweyr.Eng.Sun.COM Tue Nov 21 13:54 PST 1995
Date: Tue, 21 Nov 1995 13:54:27 -0800
From: flar@bendenweyr.Eng.Sun.COM (Jim Graham)
To: aleph1@dfw.net, jshermer@BASISinc.com
Subject: Re: Simple Draw Image
Cc: java-interest@java.Eng.Sun.COM


Hi Jill,

> Hmmm,  I have figured out, by resizing my appletviewer window to
> cover my root window, that the first image in my image loop is drawn to
> a very large scale before my image loop is drawn.  That is why I
> am seeing this unexpected top-left border interferring with my expected image
> loop.  How do I turn this off?   Any clues?

There is nothing inherent in the image drawing code that draws your
image to a very large scale for you, you have to be doing that yourself.

Without seeing your code, it sounds as if you are using the scaling
version of drawImage (drawImage(img, x, y, w, h, this)) with improperly
initialized variables for the width and height parameters.  If you don't
want scaling, then just use the regular method (drawImage(img, x, y, this)),
otherwise, make sure that the width and height you are requesting are
the width and height you really want (i.e. the variables you are using
have been properly initialized with the dimensions you want).

				...jim


----- End Included Message -----

----------
X-Sun-Data-Type: default
X-Sun-Data-Description: default
X-Sun-Data-Name: WizardItem.java
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 182

/*
 * @(#)Wizard.java	
 *
 * Copyright (c) 1994-1995 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
 * without fee is hereby granted. 
 * Please refer to the file http://java.sun.com/copy_trademarks.html
 * for further important copyright and trademark information and to
 * http://java.sun.com/licensing.html for further important licensing
 * information for the Java (tm) Technology.
 * 
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 * 
 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
 * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  SUN
 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
 * HIGH RISK ACTIVITIES.
 */

import java.io.InputStream;
import java.applet.Applet;
import java.awt.*;
import java.net.*;

/**
 * A simple Item class to play an image loop.  The "img" tag parameter
 * indicates what image loop to play.
 *
 * @author 	James Gosling
 * @version 	1.17, 31 Jan 1995
 */
public
class WizardItem extends Applet implements Runnable {
    /**
     * The current loop slot.
     */
    int loopslot = 0;
    /**
     * The directory or URL from which the images are loaded
     */
    String dir;

    /**
     * The thread animating the images.
     */
    Thread kicker = null;

    /**
     * The length of the pause between revs.
     */
    int pause;
    int speed;
    int nimgs;

    /**
     * The images.
     */
    Image imgs[];

    /**
     * The offscreen image.
     */
    Image im;

    /**
     * The offscreen graphics context
     */
    Graphics	offscreen;

    int maxWidth;
    int maxHeight;



    /**
     * Initialize the applet. Get attributes.
     */
    public void init() {
	//System.out.println("WizardItem.init");
	String at = getParameter("img");
	dir = (at != null) ? at : "images";
	at = getParameter("pause");
	pause = (at != null) ? Integer.valueOf(at).intValue() : 3900;
	at = getParameter("speed");
	speed = (at != null) ? (1000 / Integer.valueOf(at).intValue()) : 100;
	at = getParameter("nimgs");
	nimgs = (at != null) ? Integer.valueOf(at).intValue() : 9;
	at = getParameter("maxwidth");
	maxWidth = (at != null) ? Integer.valueOf(at).intValue() : 102;
	at = getParameter("maxheight");
	maxHeight = (at != null) ? Integer.valueOf(at).intValue() : 128;

    }

    /**
     * Run the image loop. This methods is called by class Thread.
     * @see java.lang.Thread
     */
    public void run() {
	//System.out.println("WizardItem.run");
	Thread.currentThread().setPriority(Thread.NORM_PRIORITY-1);
	imgs = new Image[nimgs];
	for (int i = 1; i < nimgs; i++) {
	    imgs[i] = getImage(getDocumentBase(),dir + "/Wizard" + i + ".gif");
	}

	Dimension d = size();
	if (nimgs > 1) {
	    while (kicker != null) {
		//System.out.println("frame = " +  loopslot);
		if (++loopslot >= nimgs) {
		    loopslot = 0;
		}
		repaint();
		try {
		    Thread.sleep(speed + ((loopslot == nimgs - 1) ? pause : 0));
		} catch (InterruptedException e) {
		    break;
		}
	    }
	}
    }

    public boolean imageUpdate(Image img, int flags,
			       int x, int y, int w, int h) {
	if ((flags & (SOMEBITS|FRAMEBITS|ALLBITS)) != 0) {
	    if ((imgs != null) && (loopslot < nimgs) 
			       && (imgs[loopslot] == img)) {
		repaint(100);
	    }
	}
	return (flags & (ALLBITS|ERROR)) == 0;
    }

    /**
     * Paint the current frame.
     */
    public void paint(Graphics g) {
	//System.out.println("paint");
	if ((imgs != null) && (loopslot < nimgs) && (imgs[loopslot] != null)) {
//	    im = createImage(102, 128);
//	    offscreen = im.getGraphics();
//    	    offscreen.setColor(Color.lightGray);
//	    offscreen.fillRect(0,0,102,128);
//	    offscreen.drawImage(imgs[loopslot], 0, 0, this);    
//	    g.drawImage(im, 0, 0, this);
	    g.drawImage(imgs[loopslot], 0, 0, this);
	}
    }

    /**
     * Start the applet by forking an animation thread.
     */
    public void start() {
	if (kicker == null) {
	    kicker = new Thread(this);
	    kicker.start();
	}
    }

    /**
     * Stop the applet. The thread will exit because kicker is set to null.
     */
    public void stop() {
	if (kicker != null) {
	    kicker.stop();
	    kicker = null;
	}
    }
}
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post