Your DrawingPane seems to have a list of Rectangle named circles (sic). I don't know if Rectangle is one of your classes or the standard java.awt. Rectangle If it's one of your class, then simply add a color attribute to this class, and get this attribute from it during your iteration If it's the standard java.awt.
Rectangle then introduce a Circle class, containing a Rectangle and a color, and use a list of Circle rather than a list of Rectangle.
Your DrawingPane seems to have a list of Rectangle named circles (sic). I don't know if Rectangle is one of your classes or the standard java.awt.Rectangle. If it's one of your class, then simply add a color attribute to this class, and get this attribute from it during your iteration.
If it's the standard java.awt. Rectangle, then introduce a Circle class, containing a Rectangle and a color, and use a list of Circle rather than a list of Rectangle.
It is the standard ava.awt. Rectangle – arjacsoh Oct 18 at 15:45.
I want to be able to deploy the color as a parameter and to invoke the method from another method in another class Then you need to store the Color and shape as properties of a custom class. Custom Painting Approaches shows an example of how to do this. I would use the DrawOnComponent example as a starting point.
Your code will be much simpler since you don't need to handle dragging. All you need to do is create an addCircle(...) method which will take the size/location/color of the circle as parameters.
You are free to declare the classes MyCircle and DrawingPane in separate . Java files. I am sure that this will give answer to " I want to be able to deploy the color as a parameter and to invoke the method from another method in another class.
" public class TestingX12 { public static void main(String args) { new TestingX12(); } public TestingX12() { //create list of circles List circList = new ArrayList(); circList. Add(new MyCircle(new Rectangle(100, 20, 120, 30), Color. Red)); circList.
Add(new MyCircle(new Rectangle(150, 50, 80, 50), Color. Yellow)); circList. Add(new MyCircle(new Rectangle(30, 90, 30, 110), Color.
Blue)); DrawingPane dp = new DrawingPane(circList); JFrame frame = new JFrame("JToolTip Sample"); frame. SetDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); frame.
SetContentPane(dp); frame. SetSize(400, 450); frame. SetVisible(true); } class MyCircle { Rectangle rectangle; Color color; public MyCircle(Rectangle r, Color c) { this.
Rectangle = r; this. Color = c; } } public class DrawingPane extends JPanel { List circles; public DrawingPane(List circles) { this. Circles = circles; } protected void paintComponent(Graphics g) { super.
PaintComponent(g); Rectangle rect; for (int I = 0; I Rectangle; g. SetColor(circles. Get(i).
Color); g. FillOval(rect. X, rect.
Y, rect. Width, rect. Height); System.out.
Println("Drawing..."); } } } }.
It is good on the base of what I asked. Thanks. – arjacsoh Oct 18 at 18:08.
I'm not sure what you mean, but if you're trying to set the circle colors from an outside class, then make the array a property of the class with a setter and (if needed) a getter: public class DrawingPane extends JPanel { private Color colors; public void setCircles(Color colors) { this. Colors = colors; repaint(); } protected void paintComponent(Graphics g) { super. PaintComponent(g); Rectangle rect; if (colors!
= null) { for (int I = 0; I FillOval(rect. X, rect. Y, rect.
Width, rect. Height); } } } }.
Your array of colors is sometimes called colors, and sometimes circles. And circles is also the list or Rectangles. – JB Nizet Oct 18 at 15:46 @JBNizet: thanks!
Fixed, I think, although I somewhat confused by the original post. – Hovercraft Full Of Eels Oct 18 at 17:59.
I have found this class that draws circles with different colors. The color of each circle is determined according to a specific order of colors which iterates as it comes to the end (having used all colors by one time). I want to modify this on a way that grants me the potential to determine individually the color (on g.
SetColor) for each circle. In other words, I want to be able to deploy the color as a parameter and to invoke the method from another method in another class. If you find my question stupid I would like to let you know that what worries me is the fact that the method is inherited from JPanel and I am not sure how to override it effectively.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.