• 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

Java 2D method + GTK

 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In an introductory book on Java, a simple method for doing Java 2D graphics is described in these steps:
1. Extend JPanel
2. override void paintComponent(Graphics g)
3. cast (Graphics g) to (Graphics2D)
4. use the J2D API from here.

Is this the only way, or was this just a simple introduction? The reason I ask is that there are some faults with it. The two main problems I have are:
1. The drawing flickers every time i move the JFrame containing it.
2. It won't seem to compile with gij under linux! i get the error

java.lang.ClassCastException: gnu.java.awt.peer.gtk.GdkGraphics cannot be cast to java.awt.Graphics2D

Chris
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gcj is wrong here in not using Graphics2D objects. That's par for the course, though; Gcj doesn't conform to every little wrinkle of Sun's Java implementation. You can use (and frankly, should be using) Sun's JDK on Linux, and then of course this problem will go away.

The flickering shouldn't happen; are you calling super.paintComponent() in your implementation?
 
Christopher Arthur
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Now that I've downloaded the Sun JVM, I'm not getting exceptions anymore.

No, I'm not calling super.paintComponent() anywhere. When should that be done? Actually the flickering seems to happen every time I click on the frame.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should pretty much always call super.paintComponent() as the first line of a paintComponent() implementation.

A JPanel should be double-buffered by default, which should eliminate any flickering; are you, by chance, using one of the constructors that lets you turn this feature off?
reply
    Bookmark Topic Watch Topic
  • New Topic