| CPSC 124 | Introduction to Programming | Spring 2008 |
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.
Create a lab11 directory in your cs124 directory to hold the files for this lab.
Copy the files from /classes/s08/cs124/labs/lab11/ to your lab11 directory.
Here are the exercises for this week's lab, due at the beginning of next week's lab.
Write a program called MyPicture.java that displays a window with a simple picture on it. You may not use Paint.java, but rather your MyPicture class should extend JPanel and override the paintComponent method. When building the window in the main method, you should set the content pane to new MyPicture object. See your class notes for how to do this.
Your picture should include at least 5 shapes, 3 colors, and some text. It does not have to be an elaborate picture. It could be as simple as a snowman, smiley face, etc. In fact, don't spend a lot of time on your picture unless you have finished the other two exercises.
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 (note: a panel counts as a component) 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. It also should be functional in some way, i.e., it should do something. What it does could be very simple, but you should not have things on your window that serve no purpose.
Here are a couple of ideas you might try:
Feel free to implement something different than the two examples above. In addition, feel free to modify the two examples if you want to do something similar but slightly different. Extra credit will be awarded for nifty programs.
Write a program called DrawShapes.java that allows a user to select between three shapes (ovals, rectangles, or lines), several colors (e.g., blue, red) and draw the corresponding figure on the window. Within the directory you copied is a working program called DrawShapes that will allow you to run the program and see how it is supposed to work. Your program should eventually work like this one. It is not a Java program, however, so you cannot run it in the same way you run other programs. To run it, go to the directory containing DrawShapes and type "./DrawShapes &" and hit enter. For extra credit, add other shapes such as triangles or other functionality (beyond simply new colors).
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/cs124/username (where username is replaced with your username).