Step 2

Preparing the paint function


Next, above the “main” function, add the code as shown here to create the “paint” function.

This function gets called every time the window uses the “repaint” function we called earlier, so this code will be used multiple times.

First off, we use the “paint” function of the parent class, since it has some necessary and complicated code we don’t really need to worry about.

We then convert our Graphics variable “g” into a “Graphics2D” variable. The “Graphics2D” class is an advanced class that makes drawing things relatively easy.

Lastly, we turn on something called “Anti-aliasing”, this will help make our drawings a lot smoother.

After this, we are all ready to start drawing on our window. The next section will show you how to draw certain shapes, but they are not how your code needs to look. These are just the tools, in this project, try and use these tools to create/draw something unique!