• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JApplets, can't seem to draw anything

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 geocities.com (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
reply
    Bookmark Topic Watch Topic
  • New Topic