As always, feel free to ask lots of questions, and feel free to work together as well!
Canvas
classIn your Projects folder, create a subfolder
called graphicsIntro
to hold your work for this lab.
Copy the file Canvas.java
to the graphicsIntro
directory that you just created. To do
so, right click on the link and choose "Save Link As..."
You can open up the file and look at it if you'd like. However, we won't be paying much attention for a while to what's in this class. Instead, we're going to use this class in our own programs.
Now copy the file MyArtwork.java to your directory and open it up in DrJava. Read through the code and see if you can figure out what it will do.
Compile and run MyArtwork. What do you see? Try modifying the program to accomplish the following:
The documentation for the Canvas class is at this web page. Notice that the page has distinct sections: a general description of the class, a summary of fields and constructors (we'll talk about those later), and a more detailed description of all the methods available to you. Take a few minutes to skim the methods and to familiarize yourself with the documentation format. Then try picking out a few methods that look like they might be interesting, and try them out. Modify your program to use other methods from this documentation page. (Note that the polygon methods require ideas we haven't covered yet, so you might want to stay away from them unless you feel particularly daring.)
Write a Java application named MyDrawing.java
. Your
program should create a Canvas
object and, using the
methods in the Canvas
class, draw a picture. Spend a
little bit of time experimenting with the different methods, and then
figure out how to combine these methods to draw more complex shapes or
pictures. Use the arithmetic operations that you learned in the last
assignment as part of your program.
Some suggestions:
wait()
and erase()
methods to erase part of the picture. (If you're really feeling ambitious, you might want to figure out how you could use these methods to make it appear as if something is moving across your canvas.)Be creative, and have fun!