Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Drawing multiple circles in a panel



Hi all,
I am trying to draw multiple circles (actually arcs to make one circle) on top of one another in a panel. 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.
I have to problems.
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.
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.


Here is my circle drawing class:
public class CircleDraw extends JPanel{
//create loop of colors to associate with the notes of the scale
Color[] pieColors = {new Color(255,255,255,20), //Silent WHITE
new Color(255,0,0,20), //A RED
new Color(191,64,0,20), //A#
new Color(128,128,0,20), //B
new Color(64,191,0,20), //C
new Color(0,255,0,20), //C# GREEN
new Color(0,191,64,20), //D


new Color(0,128,128,20), //D#
new Color(0,64,191,20), //E
new Color(0,0,255,20), //F BLUE
new Color(64,0,191,20), //F#
new Color(128,0,128,20), //G
new Color(191,0,64,20)}; //G#


                int xPos;
                int yPos;

                int mySize;
                int panelWidth = 400;
                int panelHeight = 400;

                int arcRotation = 0;
                int numbOfSlices = numbOfNotes;
                int arcAngle = 360/numbOfSlices;

public CircleDraw(int size){
super();
setPreferredSize(new Dimension(panelWidth,panelHeight));
this.mySize = size;
 
}
public void paint(Graphics g){
xPos = (panelWidth/2)-(mySize/2);
yPos = panelHeight/2-(mySize/2);
Graphics2D myG = (Graphics2D)g;
for(int i=0;i<numbOfSlices;i++){
 
myG.setColor(pieColors[notesInMelody[i]]);
myG.fillArc(xPos,yPos,mySize,mySize,arcRotation,arcAngle);
arcRotation += arcAngle;
}



} }


and I call it in a method that gets called by a thread every 500 ms.

public void drawCircle(){
circleArray[melodyCounter] = new CircleDraw(400);
System.out.println("MelodyCounter = "+melodyCounter);
centerPanel.repaint();
for(int i=0;i<=melodyCounter;i++){
circleArray[i].mySize = 400-(i*10);
System.out.println("Size"+i+" = "+circleArray[i].mySize);
centerPanel.add(circleArray[i]);
}
melodyCounter++;
}




I would really appreciate any help. I can't get it.

Jay
_______________________________________________
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


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.