AWT problem on linux

Peter C. Mehlitz peter at transvirtual.com
Thu Sep 3 03:33:03 PDT 1998


>On Thu, Sep 03, 1998 at 12:27:07AM +0200, Diego Santa Cruz wrote:
>> I've found the problem.
>> The problem was that I did not wait until the image dimensions became available
>> and thus it was setting the component size to (-1,-1) which made the window of
>> just 1 pixel in height and extreamely large in width (several thousands pixels).
>> The problem did not show up in Sun's JDK since there the dimensions are
>> immediately available. I just added a loop with a sleep to wait for the
>> dimensions.

No, sleeping isn't the right way to do that. I append a solution that
plays it according to the specs.

If you try this with a small image, you will notice that the Frame size isn't a
exact match. This is due to a Frame size inconsistency we could easily solve
(by removing some code), but which would make it even more "incompatible" with
JDK behavior (NOT specs). This is subject to my next message.

-- Peter

-------------------------------------------------------------------
import java.awt.*;
import java.awt.image.*;

public class Img extends Frame {
	Image img;
	public Img ( String title ) {
		super( title);
	}
	void showIt () {
		setSize( img.getWidth(this), img.getHeight( this));
		setVisible( true);
	}
	public void setImage ( String imgSpec ) {
		Toolkit tk = getToolkit();
		img = tk.getImage( imgSpec);
		if ( tk.prepareImage( img, -1,-1, this) )
			showIt();
	}
	public boolean imageUpdate ( Image img, int info, int x, int y, int w, int h ){
		if ( !isShowing() &&
			 ((info & ImageObserver.WIDTH) != 0) &&
			 ((info & ImageObserver.HEIGHT) != 0) ) {
			showIt();
			return true;
		}
		return super.imageUpdate( img, info, x, y, w, h);
	}
	public void paint ( Graphics g ) {
		Insets in = getInsets();
		g.drawImage( img, in.left, in.top, this);
	}
	public static void main ( String[] args ) {
		Img v = new Img( "Image Test");
		v.setImage( args[0]);
	}
}


More information about the kaffe mailing list