• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using a back buffer

 
Nate Lockwood
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rob Spoor
Sheriff
Pie
Posts: 20493
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:
Nate Lockwood wrote:I have a class that extends Canvass

Since that's not a class in the standard JDK

Not?
 
Nate Lockwood
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not Canvass


Auto-correct failure...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic