| Author |
Using a back buffer
|
Nate Lockwood
Ranch Hand
Joined: Feb 22, 2010
Posts: 75
|
|
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: 4166
|
|
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: 19216
|
|
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
How To Ask Questions How To Answer Questions
|
 |
Nate Lockwood
Ranch Hand
Joined: Feb 22, 2010
Posts: 75
|
|
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: 4166
|
|
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: 75
|
|
That's not Canvass
Auto-correct failure...
|
 |
 |
|
|
subject: Using a back buffer
|
|
|