LCCC Course CIS 210 - Java Programming

Java Programming Assignment 3

Modify the PetRockApplet program to:

* Make your pet a circle or oval rather than a rectangle See your instructor or textbook for drawing methods
* Make sure it is “your” pet. (i.e. change the name)
* Change the color - see your instructor
* Make sure you comment and indent properly!!!
* Bonus if you have two buttons: one to flip the rock one to change colors

To modify your PetRock to change colors :

1. You will need to declare two instance variables for the colors (you'll have to decide where in the class to put these two lines):

private Color color1;
private Color color2;


2. You will need to define (initialize) the color variables (you'll have to decide which method to these to lines):

color1 = Color.red;
color2 = Color.blue;

3. How should you write another method like the flip() method that will swap the colors?

4. How should you modify the paint() method to use color1?

Bonus Assignment:

* Use an oval and have 2 buttons (one to flip and one to change color)

public void actionPerformed(ActionEvent e)
{ 
   if (e.getSource() == flipButton)	// check if flipButton was clicked
   {       
        flip(); 
   }
   if (e.getSource() == colorButton)	// check if colorButton clicked
   { 
        changeColor(); 
   } 
   repaint();	// redraw the picture
 }	// this ends the actionPerformed method

www.lc.edu

Last Updated: January, 2011