Skip to main content

getting pixel color information from a rectangle inside a Panel

2 replies [Last post]
Anonymous

Hi to everyone,

i have built a graphics application using only AWT.
Inside a Panel i illustrate a graph which has a number of nodes and arcs
(i have drawn THE GRAPH using g.fillOval and g.drawLine methods).
What i want to achieve is to move a red node (circle) from one point P1 inside the
Panel to another Point P2.
I have done it as follows:
..
while (P1!=P2){
draw the node in red color(fillOval)
delay(100ms)
draw the node in white color(fillOval)
move P1
}
The problem is that as the node is moving it ERASES any previous pixels
lying below it.
Is there any way to get the color of these pixels that lie below the moving node
and DRAW IT ONLY if those pixels are white?

Thanks in advance
Thanasis

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
[att1.html]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Jim Graham

Depending on the complexity of your drawing, simply rerendering the
scene with the objects in the new position (with double buffering) may
work well for 10 frames/second performance. Switch to using Swing with
a JPanel (you'll have to override paintComponent instead of paint) and
call repaint() every 100ms instead of drawing it directly.

If your scene is complicated, though, then a layering solution as others
have suggested can help with the performance...

...jim

Thanasis (Hotmail) wrote:
> Hi to everyone,
>
> i have built a graphics application using only AWT.
> Inside a Panel i illustrate a graph which has a number of nodes and arcs
> (i have drawn THE GRAPH using g.fillOval and g.drawLine methods).
> What i want to achieve is to move a red node (circle) from one point P1 inside the
> Panel to another Point P2.
> I have done it as follows:
> ..
> while (P1!=P2){
> draw the node in red color(fillOval)
> delay(100ms)
> draw the node in white color(fillOval)
> move P1
> }
> The problem is that as the node is moving it ERASES any previous pixels
> lying below it.
> Is there any way to get the color of these pixels that lie below the moving node
> and DRAW IT ONLY if those pixels are white?
>
>
> Thanks in advance
> Thanasis
>
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Chet Haase

Seems like you want some buffer that holds the contents
of the graph without your red node on it. Then prior to
drawing the new location of the red node, you can simply
copy in the contents from the buffer in the area affected by
the last rendering of the red node. This will effectively
"erase" the red node from its previous location. (It may also
be faster than drawing a new oval in that location, as a
side benefit)

Chet.

Thanasis (Hotmail) wrote:
> Hi to everyone,
>
> i have built a graphics application using only AWT.
> Inside a Panel i illustrate a graph which has a number of nodes and arcs
> (i have drawn THE GRAPH using g.fillOval and g.drawLine methods).
> What i want to achieve is to move a red node (circle) from one point P1
> inside the
> Panel to another Point P2.
> I have done it as follows:
> ...
> while (P1!=P2){
> draw the node in red color(fillOval)
> delay(100ms)
> draw the node in white color(fillOval)
> move P1
> }
> The problem is that as the node is moving it ERASES any previous pixels
> lying below it.
> Is there any way to get the color of these pixels that lie below the
> moving node
> and DRAW IT ONLY if those pixels are white?
>
>
> Thanks in advance
> Thanasis
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body of the message "signoff JAVA2D-INTEREST". For general help, send
> email to listserv@java.sun.com and include in the body of the message
> "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".