Article View: borland.public.jbuilder.java.api
Article #1017Re: help, GUI redrawing is obviously confusing me
From: John McGrath TeamB
Date: Mon, 29 Apr 2002 04:14
Date: Mon, 29 Apr 2002 04:14
40 lines
2498 bytes
2498 bytes
On Sun, 28 Apr 2002 20:19:34 -0400, PeterH wrote:
> Here's the class:
There is no main() method in any of this so I cannot run it to see what
it is doing. However, there are two things that I noticed:
1) You have a paint() method and a paintComponent() method and they
both seem to do more or less the same thing. Under most circumstances
with a Swing component, you should override paintComponent() and leave
the paint() method alone.
Since your paint() method does not always paint the entire area of the
Photo component, this is likely the cause of the double image you are
seeing.
Get rid of the paint() method, and call super.paintComponent() at the
top of your paintComponent() method, and that should go away.
2) I see you have imported MediaTracker, but you do not use it. And in
several of the methods, you try to scale the image using the width and
height obtained from the image. Since the image might not be loaded,
the width and height returned might be negative, which will probably
cause image.getScaledInstance() to choke.
You can either use a MediaTracker to ensure that the image has been
entirely loaded or return an empty image when the underlying image has
not been loaded.
If that does not solve your problem, I will try running it if you can
provide a main() program with which to to run it.
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID:
<MPG.17367eed5c1d13b498b5a5@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!peer.news.opaltelecom.net!out.nntp.be!propagator2-SanJose!propagator-SanJose!in.nntp.be!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsReferences:
<3cca1147_2@dnews> <MPG.17343aafe3bf00ad98b59e@newsgroups.borland.com> <3ccc933c_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,da4fdf29b67dc0d2 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2002-04-28 21:27:11 PST From: John McGrath [TeamB] <ng-b@JPMcGrath.net> Newsgroups: borland.public.jbuilder.java.api Subject: Re: help, GUI redrawing is obviously confusing me Date: Mon, 29 Apr 2002 00:14:48 -0400 Message-ID: <MPG.17367eed5c1d13b498b5a5@newsgroups.borland.com> References: <3cca1147_2@dnews> <MPG.17343aafe3bf00ad98b59e@newsgroups.borland.com> <3ccc933c_2@dnews> X-Newsreader: MicroPlanet Gravity v2.60 NNTP-Posting-Host: 209.92.40.60 X-Trace: dnews 1020053686 209.92.40.60 (28 Apr 2002 21:14:46 -0700) Lines: 40 X-Authenticated-User: jpmcgrath Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!peer.news.opaltelecom.net!out.nntp.be!propagator2-SanJose!propagator-SanJose!in.nntp.be!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews