Re: paint program

From: Alex Hunsley (lard_at_tardis.ed.ac.molar.uk)
Date: 09/22/04


Date: Wed, 22 Sep 2004 18:27:57 GMT

Paul Lutus wrote:
> John Davison wrote:
>
> / ...
>
>
>>I'm guessing that Java probably doesn't keep track of the color of each
>>pixel of each component. It probably just says "draw whatever" and then
>>the underlying OS takes care of the pixels. (Someone correct me if I am
>>wrong here.)
>
>
> You're wrong here.
>
>
>>But you *can* draw to an image, then draw the image onto a component.
>
>
> And you can "draw" directly onto a component, using that component's paint()
> method. This is the most efficient way to address the original problem.

It's not efficient at all - as the user builds up pixels with their
paintbrush, would you redraw every pixel at each paint?
Much more efficient/easier to draw to a buffer, then draw the buffer (or
part thereof) to the screen when needed.
Swing *does* have double buffering built in, but it is per-paint time
and not a persistent image, which is what the OP needs from the sound of it.

Also, it's a good idea to override paintComponent rather than paint -
paint calls paintComponent amongst other things (like paintChildren and
paintBorders).

alex



Relevant Pages

  • Re: Display special characters on a JEditorPane
    ... paintComponent so that you insert the glyphs when you paint, ... don't actually exist in the text buffer. ...
    (comp.lang.java.gui)
  • Re: paint program
    ... Alex Hunsley wrote: ... > paintbrush, would you redraw every pixel at each paint? ... > Much more efficient/easier to draw to a buffer, ... it's a good idea to override paintComponent rather than paint - ...
    (comp.lang.java.programmer)
  • Re: paint program
    ... Alex Hunsley wrote: ... > paintbrush, would you redraw every pixel at each paint? ... > Much more efficient/easier to draw to a buffer, ... it's a good idea to override paintComponent rather than paint - ...
    (comp.lang.java.gui)
  • Re: Basic Restoration Questions
    ... suppose you could use the buffer for the bolts but I wouldn't ... I put it on a rag and rub it in to the areas where the paint ... after getting them clean, I run them on the buffer ... Just watch out using a buffer wheel since that thing can snatch the ...
    (rec.games.pinball)
  • 560 out of 563 Pixel Per Line?
    ... It seems to be extra 3 pixels in the right farther from position 559. ... it will only show 560 x 192 resolution instead of ... you please explain why it is the way how NTSC uses extra 3 pixels? ... dark green color does not paint in position 0 and position 1 and brown color ...
    (comp.sys.apple2)