File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes JApplets, can't seem to draw anything Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "JApplets, can Watch "JApplets, can New topic

JApplets, can't seem to draw anything

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
Hi, this post kind of follows on from my last.
I've been advised to use JApplets to avoid the screen flashing
problem when repaint() is called.

I've written a very short JApplet (below), and I'm trying to get it to
draw a line, but its not working. I've been messing around with it for
a couple of hours now, and I can't see why it won't draw.
Also, usually when I extend the JPanel class in an application, I would
override paintComponent(Graphics g), and in this implementation, I would
make the call super.paintComponent(g), however this doesn't seem to
compile in this JApplet.

I'd be very grateful if someone could explain why this applet isn't drawing
the line like its supposed to. Thanks
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
I've placed a System.out.println("...") statement inside the
paintComponent(Graphics g) method, and this clearly shows that
paintComponent is being invoked when repaint() is called.
So I'm not sure, I'm gonna have a look at some JApplet info from sun, and
see if I can figure it out.

Thanks again for any help.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
OK, I've kind of figured it out.
I still need to extend JPanel in order to use paintComponent(...)
So I've created an inner class within the JApplet to do the drawing.
I knew inner classes would come back to haunt me at some point.
Maybe I could write this class separatley, but I'm not sure if this
will work with (free web site creator). I'm currently just
uploading the one applet class file, and I'm not totally sure if I can upload 2 class files and it will work.
I'll let you know if I get stuck, thanks
I agree. Here's the link:
subject: JApplets, can't seem to draw anything
It's not a secret anymore!