Jason Smalridge wrote:
>I am trying to draw multiple circles (actually arcs to make one circle) on
>top of one another in a panel.
Are the circles filled or stroked (outlined) or both? I don't have a
precise mental picture of what "draw" means here. I have even less of a
picture of how the arcs and concentric circles or arcs work.
Are you trying to emulate an animation of some kind? If so, what?
Exactly what is the context for your question? It looks to me like a
homework problem for a programming course, but I'm just guessing.
Personally, I'm reluctant to give you complete homework answers, but I'm
happy to point you to resources or offer suggestions.
What is your Java experience level? If you haven't worked a lot with Swing
components, you should at least browse the Swing tutorial:
<http://java.sun.com/docs/books/tutorial/uiswing/TOC.html>
>What I want is to draw one circle (c1) in a panel, then after some time
>erase the panel and redraw c1 a little smaller and draw a second circle(c2)
>on top at the original size of c1. This will continue as more circles are
>drawn on top of the previous circle which decrease in size each time
>creating a sort of tunnel(each circle a low alpha so you can see what is
>behind it.
Another algorithm that produces the same results (concentric circles) is to
not change the size of any circle once it's drawn, just add a new circle
that's smaller than its predecessor. (How that fits in with the arcs you
mentioned, I don't know. I don't get a mental picture from your
description or your code, so I don't understand what you're trying to do
with arcs.)
To draw concentric circles:
Draw C1 with diameter D. Draw C2 with diameter D-K, where K is the
"shrinkage" amount at each time-step. At each iteration, reduce the
diameter further, so C3 is D-2K, etc. The diameter is D-(i*K), where i is
the index (or position in time or array) of that circle.
>First I can't seem to get the circles to draw on top of each other. Each
>time I draw another circle it erases the first circle so that the newest
>circle is the only one that shows.
I suggest a different strategy than the one you've adopted. Instead of a
JComponent per circle, which are then added to a JPanel, define a single
class that handles all the circles and circle-drawing. You can simply
subclass JComponent to do this, and there's only one instance per "tunnel"
drawn.
If you insist on a JComponent per circle, you'll have to set each component
to non-opaque, and make sure it works correctly when it completely overlaps
other components. In general, components are mostly intended to be
non-overlapping, so that strategy goes against the grain of JComponent,
JPanel, etc.
Also, if all your JComponents are at the same location in the parent
JPanel, the panel itself needs an appropriate layout manager, appropriate
Z-layer management, and so on. Do you really want to learn all that just
to draw concentric circles, when a single JComponent would work as well?
>Second, I created an array of my circle object that holds the circles as
>they are created. What I need to do is to push back the first circle to the
>second position in the array when a second one is created and on and on
>like that.
See java.lang.System.arraycopy():
<http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html>
Or walk the array of circles backwards. You add new ones at the end of the
array, and draw them from highest index to lowest, which will be newest to
oldest.
Or if you want to draw largest to smallest, and no circle's diameter ever
changes (per above), add to the end of the array and draw from index 0
upwards. Or to draw smallest to largest, add to end of array and draw from
highest valid index downwards.
-- GG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden
This email sent to email@hidden