Re: PaintComponent Does not 'Fire'
Andrew Thompson wrote:
On Apr 30, 8:23 am, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
wrote:
...
Extending paintComponent() of a JFrame will probably only give you
grief. ...
Probably?
<sscce>
import java.awt.Graphics;
import javax.swing.JFrame;
class OverridePaintComponentInJFrame extends JFrame {
@Override
public void paintComponent(Graphics g) {
// ...
}
}
</sscce>
Try drawing something and see what happens :-).
I disagree slightly with your advice to check for
null in paint/paintComponent. I agree the check should
not be doen in that section of the code, but feel it
should be done, once after the image is supposedly
obtained. OPs complaining that the IDE can find their
image but 'java' cannot is the next most common problem
with code of this nature.
The null check can be safely omitted only in the case where you use the
Toolkit to load the image and the ImageObserver to draw with. If you
use some other asynchronous method to load the image and
paintComponent() is called before the image is loaded you will most
likely get a NullPointerException.
--
Knute Johnson
email s/nospam/knute2009/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access