CPSC 124 Introduction to Programming Spring 2007

Lab 11: Graphics

This weeks labs will focus on graphics in Java (from chapter 6 in the textbook). It will help you get started doing project 3 (the graphics for the SnakePit game), which is due in 2 weeks.

Setup

Create a lab11 directory in your cs124 directory to hold the files for this lab.

Copy the files from /classes/s07/cs124/labs/lab11/ to your lab11 directory.

Exercises

Here are the exercises for this week's lab, due at the beginning of next week's lab.

  1. Write a program called MyWidgets.java that displays a window with a number of components (buttons, text areas, text fields, selectors, etc.). Your window should have at least 5 components and use at least two different layouts (which means you will need to add a panel to a panel). You must design a program that is substantially different from the programs presented in class. Extra credit will be awarded for nifty programs.

  2. Write a program called MyPicture.java that displays an interesting picture. You should draw a different picture than the one you drew in lab 3 (and you can't use Paint.java). Your program should use two classes (both classes should be written within the file MyPicture.java). The first class, MyPicture, will build the window. It will also contain the main() method. The second class, called DrawingBoard, will display the graphics. It should extend the JPanel class and override the paintComponent() method as we discussed in class. In MyPicture, when you create the window, you should construct a DrawingBoard object and set it to be the content panel of the window. Use your class notes or chapter 6 of the book as a guide for how to do this. Note: you will not need any listeners in this exercise.

    In DrawingBoard, you will draw the actual picture. As in lab 3, extra credit will be awarded for nifty and interesting pictures. Use the methods on pages 245-246 of the book to draw various shapes (these methods are named similarly to the ones in Paint.java from lab 3).

Handin

Verify that your lab11 folder contains all of the files you created or modified for this lab, then copy your entire lab11 folder to the handin directory ~mcorliss/handin/124/username (where username is replaced with your username).