From: "Simon Cooke (Exchange)" 
To: "'Chotank@aol.com'" 
Subject: RE: Code Sample??
Date: Wed, 10 Feb 1999 13:02:06 -0800

Simon,

Sorry, for the delay with a reply.  I have been waiting to see if any of the
readers of your comments could find flaws in your recommendations. No one
else
has.

---

Hey, no problem :)

---

However, I do.  If Toolkit should not work, why does it run fine in IE 5.0
beta?  You already know that Netscape 3.0 forward handles the MyCHOFlow
code.
And if you go to www2.una.edu/communications/, you will find an implementation of Toolkit
which WILL load an image in a separate applet frame,  running under IE 4.0.
Look for the lion in the upper-right corner after clicking on JAVA-Powered
link.

---

I've just had a look at that file, and have decompiled it with mocha, and
have run a windiff.

Let's take a look at this:

BTW: Lines starting with !! come from tUnaLeo, lines starting with a !> come
from MyChoFrame; lines
with no markers indicate common lines in both files.

    import java.awt.*;
    import java.io.PrintStream;
    import java.net.MalformedURLException;
    import java.net.URL;
    
 !! synchronized class tUnaLeo extends Frame
 !> synchronized class MyCHOFrame extends Frame
    {
 !!     static Image deptimage;
 !>     static Image meltimage;
        static String where;
        static URL url;
 !!     Insets insets;
    
 !!     tUnaLeo(String string)
 !>     MyCHOFrame(String string)
        {
            super(string);
 !!         addNotify();
 !!         insets = getInsets();
 !!         setSize(insets.left + insets.right + 204, insets.top +
insets.bottom + 95);
 !!         setBackground(Color.white);
 !>         setBackground(Color.blue);
            pack();
        }
    
 !>     public Insets insets()
 !>     {
 !>         return new Insets(0, 20, 0, 20);
 !>     }
 !> 
 !>     public void update(Graphics g)
 !>     {
 !>         paint(g);
 !>     }
 !> 
        public void paint(Graphics g)
        {
 !!         g.drawImage(deptimage, insets.left, insets.top, 204, 95, this);
 !>         g.drawImage(meltimage, 0, 20, 450, 210, this);
        }
    
        public synchronized boolean handleEvent(Event event)
        {
            if (event.id != 201)
                return super.handleEvent(event);
            hide();
            return true;
        }
    
        static 
        {
 !!         where =
"http://www2.una.edu/communications/images/leobarti.gif";
 !>         where = "http://chotank.com/classes/images/meltlogoTWO.gif";
            try
            {
                url = new URL(where);
            }
            catch (MalformedURLException e)
            {
                System.out.println(new StringBuffer("Bad
URL:").append(where).toString());
            }
 !!         deptimage = Toolkit.getDefaultToolkit().getImage(url);
 !>         meltimage = Toolkit.getDefaultToolkit().getImage(url);
        }
    }


Now, the only important thing that you different between the two is to
manually call addNotify in the one that works. You're also scaling the image
in MyChoFrame - its dimensions aren't what you're passing into the drawImage
code; which should work, but may be a bug in the IE4.0 scaling code. Insets
shouldn't make any difference, however in MyChoFrame, you're ignoring the
default insets (which are important); what you should be doing is something
like this:

public Insets insets() {
	Insets i = super.insets();
	return new Insets(i.top,i.left+20,i.bottom,i.right+20);
}
(or whatever the order is).

The Update() code calling Paint() is perfectly fine too.

So the only difference between MyChoFrame and tUnaLeo that is of any
particular interest is the
addNotify and Scaling. I'd try the scaling first; make sure that the image
dimensions you're passing in are correct - or recalc them from the
downloaded version.

The real mojo part of what you're doing is addNotify(). 99% of all layout
problems in AWT (and that includes compatibility issues between browsers)
can be fixed with judicious use of addNotify (whether overriding it, or by
calling it). However, its use is explicitly discouraged by Sun in the 1.1
docs, IIRC.

BTW: Do you have the latest Microsoft JVM? If you could download this from
http://www.microsoft.com/java and try MyChoFrame with IE4.0 again, I'd
appreciate it.

My personal guess is that either adding addNotify to your MyChoFrame code
will fix it, or making sure the image dimensions match the display
dimensions correctly will.

If it's the former, then there's nothing much you can do, other than
remember that trick for your toolbox; one thing it *DOES* do (IIRC), is to
sync everything up and create the peers for everything. So that may solve a
lot of your problems.

If it's the latter, then I'll file a bug with the JVM team for you :)

If it's something else though... we've still got some exploring ahead of us.

---

David Flanagan (O'Reilly, 1997) may not be saying what you and I have
interpreted him to say.  Should we ask Flanagan?

---

Nah... to be honest, I was kind of surprised to find the Toolkit stuff
marked as "don't use" myself; but I would recommend that you don't put UI
code or Toolkit access code inside static initialisers; you should always
ensure that you have a peer available when you're trying to do AWT work.
Also, IIRC, AWT isn't all that modeless; so changes you try to make before
the peer is created get lost sometimes.

When you think about it, using a static initialiser, loading the applet is
going to bring the class in and immediately construct it by calling the
static initialiser; it's going to be called possibly *before* the applet is
initialised, or even before any kind of peer creation occurs.

Anyway, the static stuff is my own personal rule of thumb; with these kinds
of interactions possible, I'd be careful about using a static constructor
for any kind of graphics work.

---
[snip]
Were you a member of BBCNC and/or on staff at PIPEX?  The BBC should have
kept
the organization as an international focus for BBC fans.  But then, the BBC
is
changing very rapidly.  I am looking forward to enjoying BBC America as soon
as I get my Dish TV/PC installed.
---

Actually, I was a member of the BBCNC; I wasn't working there, I just heard
about it from the BBC and signed up for an account! It was great fun... and
I've still got the modem I won :)

As for BBC America... when they stop re-showing one episode of a Tom Baker
story over and over again, I'll think about getting it :)

Have you tried http://www.beeb.com btw?

---

Have read the post to advocacy newsgroup.  Your advice and interest is
terrific.  Thank you for taking part.   Let's just forget the JVM guys.  I
will be putting a version of this on newsgroup thread.

---

Thanks *blush*.

Cool - though if we narrow this down, I'm going to fire them a bug report.

It may have been a minor glitch that got fixed when the latest version of
the Microsoft JVM was released :)

Simon (Not speaking officially for Microsoft - I work there, but they might
not share my views. Mind you, *I* might not even share my views sometimes :)
)

The following is a newsgroup exchange (comp.lang.java.advocacy) with Simon's posting coming on 9 February 1999

From: simonc@jumper.mcc.ac.uk

In article chotank@aol.com (Chotank) wrote:

>Simon says:
>
>"Don't use Toolkit . . . ."
>
>Avon says:
>
>"Simon works for Microsoft; therefore, he should know."

As I've said before . . . I'm just trying to help out, because I hate bugs : )

I'm not on the JVM team; I write UI controls for Visual Studio. So I don't have any special knowledge about this; I don't get to see the source for the MS JVM, I don't get to look at the source for the libraries; I go off the same documentation you do.

(Things are locked down pretty tight around the JVM team because of the lawsuit)

However, I do pass bug reports on to the JVM team when I can.

Simon (Not speaking officially for Microsoft)

--------== Posted via Deja News, The Discussion Network==-----------

February 22, 1999

Copyright (c) 1999, Avon Edward Foote, All Rights Reserved

Return to Exhibit