JFrame, Color, Canvas, paint, JButton, GUI
Chapter: JFrame, Color, Canvas, paint, JButton, GUI
This (optional) chapter is intended to remind you how to add components and draw simple pictures
in a Java application.
This chapter and the next consist of a series of questions to check your familiarity with
Java GUI stuff. Please review the tutorials at java.com. Do not consult the answers until you've
given the task a fair shot.

- Q. 1
- Write an application to open a new frame of size 400*400 with "Goodbye Cruel World" in the title
bar. The JFrame should be resizable and the go away box should work so that you don't
leave a zombie when you quit the program by clicking the go away box.
If you did need to consult my answer, it would be a good idea for you to add comments to the
code to make sure you understand everything. If you need to, consult the documentation, the
tutorials, Google, the lab instructor (in that order) to be sure you understand it all. Did you
notice how I declared constant SIZE to avoid magic numbers?

- Q. 2
- Same as last time, but now the JFrame will be lengthened to accomodate a 400*400 canvas whose
background color is red and two buttons, one labeled Eat Me, the other labeled Drink Me. Use a FlowLayout. We
don't need anything to work yet.
As before, if you consult my solution, check your understanding by consulting -- in order --
- the documentation,
- the tutorials,
- Google,
- the lab instructor

- Q. 3
- Now let's draw something in the canvas. Let's say a green disk of radius 50 right in the
middle of the canvas. Go ahead, you can do it. I'm going to do it by making myCanvas be
a reference to an object of an anonymous class that extends java.awt.Canvas by
having a paint method. You can do it any way you like.
As usual ... Check your understanding.
rhyspj@gwu.edu