aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Using a back buffer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Using a back buffer " Watch "Using a back buffer " New topic
Author

Using a back buffer

Nate Lockwood
Ranch Hand

Joined: Feb 22, 2010
Posts: 83
I have a class that extends Canvass that I use to display a histogram. The user can "drag" lines that are drawn over the histogram which is repainted when the mouse is moved. I noticed a flicker and wanted to draw the histogram only once in a back buffer and use it as a background for the lines drawn from the mouse move. I attempted to adapt from an example but now all I get is a light grey background. Here's some abbreviated code.

This is my first shot at using a back buffer in Java - can anyone suggest what's wrong?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Nate Lockwood wrote:I have a class that extends Canvass

Since that's not a class in the standard JDK, you need to provide more information about it.

Why don't you use Swing (extend JComponent or JPanel), which provides built-in double buffering?


luck, db
There are no new questions, but there may be new answers.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Darryl Burke wrote:
Nate Lockwood wrote:I have a class that extends Canvass

Since that's not a class in the standard JDK

Not?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Nate Lockwood
Ranch Hand

Joined: Feb 22, 2010
Posts: 83
I figured it out and the flicker is gone as I wished!
The back buffer and the lines (there's more to this than my abbreviated code of course) need to be drawn to the component Graphics object.


I had experimented with both an extended JPanel and an extended Canvas before I decided on a Canvas but can't remember exactly why - but Canvas does what I want.
BTW I did all of this in the '90s in Borland C working in Windows 98 and later Windows 95. I got it working but never did understand the graphics well. Java is better IMHO as I can understand what I'm doing.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Rob Spoor wrote:
Darryl Burke wrote:
Nate Lockwood wrote:I have a class that extends Canvass

Since that's not a class in the standard JDK

Not?

That's not Canvass
Nate Lockwood
Ranch Hand

Joined: Feb 22, 2010
Posts: 83
That's not Canvass


Auto-correct failure...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using a back buffer