all right so instead of just praying
something that's console we actually
wanted to draw something so the way
we're gonna keep track of all the shapes
is with arraylists and the way we're
gonna keep track of all these colors is
with ArrayList so if somebody draws
something anyway it's gonna make sense
when you see it so we're gonna create a
couple fields private ArrayList of shape
objects which is just a class of object
that you have to learn about and it
encompasses any number of different
shapes and so you can make one list of
all those shapes so we're gonna call
this shapes and private ArrayList of
color objects called colors and we have
to import a ray list and import shape
we've already imported color and shape
is just like a generic class for
anything that is a geometric shape in
Java so we have these two array lists no
what are we gonna do with them well
we're gonna keep track of all the shapes
that have been drawn and every time a
new shape is drawn we're gonna add it to
the list so we're actually going to do
that under Mouse drag this is gonna be
our primary method right now so what
we're going to do is we're gonna say if
if a dot get source equals panel 2 we
want to add a shape to our ArrayList so
ArrayList oops not ArrayList sorry and I
haven't initialized them and stuff up
top have I can't remember actually if I
did so let's just check that quick that
I added those two things visualize them
no I did not okay so let's initialize
them they're kind of part of the drawing
panel so on this realize I'm here shapes
equals new ArrayList shape
and colors equals new ArrayList color so
right it's a list of color objects and
the reason we're doing this is well
it'll become clear in a second so then
we head back down to our mouse dragged
stuff and we say if the mouse is dragged
on panel - we want to add shapes that
add a new we're gonna add circles
ellipse and there's just a shape that
you have to learn about called ellipse
2d double that just as a circle in Java
and you can define an ellipse and we're
gonna add it at deed get X you get Y and
we're gonna just initially we're just
gonna have this being arbitrary width
and height of 2020 and then also though
we need to keep track of what color the
person is wanting to draw so we say
colors dot add the color which is the
representation of our phone we need to
import ellipse to D of our sliders and
after that leave it or not all we have
to do is call panel dot repaint panel -
I'm sorry dot repaint and every time the
mouse is dragged it will constantly
refresh the screen because J panels know
how to do that to themselves we have
just told it to paint components now we
haven't told it yet what we would like
to actually do we just have it drawing
this box so instead of just drawing a
box we're gonna use a loop to go through
all of the items in our array lists so
we're gonna start I at the first index
and then we're gonna say I is less than
shapes dot size I plus plus and then we
want to draw a shape at that oh yeah we
want to set the color g2 set color
colors
get I and then g2 dot fill shape and we
want it to be shapes get alright and so
every time the panel is asked to repaint
itself it will scroll through all of its
list and this can be a very long list of
colors and shapes that it will it'll set
the color to whatever the color was set
when that sheep was drawn and it will
fill that shape wherever it was because
the shape remembers its own position so
if we run this I believe it'll work and
there you can see that we have a
functioning pen that is drawing that
shape and we can set the color and it
will set in fact the color okay so
that's the end of this tutorial