Currently, when I draw a line onto the drawing panel it is black. However, when each line is drawn, the color is supposed to be randomly assigned from a list of 4 possible colors. (Collections.shuffle is okay to use)
I have 3 classes: BasicLinePix, Line, and Shape.
Shape is an abstract class.
The Line class extends Shape.
I think my
method in BasicLinePix is supposed to call
from the Shape class, but everything I've tried so far hasn't worked.
I included the relevant code from each class that I believe pertains to my question. Thank you.
in your Shape class, the variable 'myColor' is only re-evaluated when you invoke the method 'setColor' of the Shape class.
As long as you do not invoke that method, myColor will remain what it is (if even initialized). So, before invoking 'getColor()', first invoke the Shape method 'setColor()'.
Note: do not confuse the method 'g.setColor' with the setColor method of the Shape class.
But why doing so complicated? Why not make the Color list a member of the Shape class (even static if you wish), and in your 'getColor()' method just return a random Color from that list. You could add a Random 'random' as field to your Shape class.
There are three kinds of actuaries: those who can count, and those who can't.