Click to See Complete Forum and Search --> : Rotating Square and circle object


Gortag
May 8th, 2010, 10:11 PM
I must create an object that will allow the user to rotate a square and a circle 90 left,90 right,180 on button click.I also need to enlarge/shrink these two shapes on button click(done this).I have attempted to make the shapes rotate,but am stuck.What am I doing wrong.I cannot use vectors or anything that complicated.Thanks.

import java.awt.Color;
import java.awt.Graphics;

public class Creature{
//definitions
private int xCoord;
private int yCoord;
private int height;
private int width;

//default constructor
public Creature (){
xCoord=0;
yCoord=0;
height=0;
width=0;


} //copy constructor
public Creature (Creature b){
xCoord=b.xCoord;
yCoord=b.yCoord;
height=b.width;
width=b.height;


}//normal constructor
public Creature(int x,int y, int w, int h){
xCoord = x;
yCoord = y;


}

//mutators(set)
//accessors(get)
public int getXCoord() {
return xCoord;
}

public void setXCoord(int coord) {
xCoord = coord;
}

public int getYCoord() {
return yCoord;
}

public void setYCoord(int coord) {
yCoord = coord;
}

public int getHeight() {
return height;
}

public void setHeight(int height) {
this.height = height;
}

public int getWidth() {
return width;
}

public void setWidth(int width) {
this.width = width;
}





public void grow(int n){
width+=n;
height=(int)(width/2);
}
public void rotate(Graphics g,boolean b){
if(b){
g.setColor(Color.green);
g.fillRect(xCoord,yCoord,height, width);
g.drawRect(xCoord,yCoord,height,width);
g.setColor(Color.black);
g.fillOval(xCoord+width/2,yCoord,height/3,width/6);



}else{
g.setColor(Color.green);
g.fillRect(xCoord,yCoord,width,height);
g.drawRect(xCoord,yCoord,width,height);
g.setColor(Color.black);
g.fillOval(xCoord,yCoord-height/3,width/6,height/3);}



}
public void move(Graphics g,boolean b){
if(b){

g.setColor(Color.green);
g.fillRect(xCoord+20,yCoord,height, width);
g.drawRect(xCoord+20,yCoord,height,width);
g.setColor(Color.black);
g.fillOval(xCoord+width/2+20,yCoord,height/3,width/6);

}
}
public void shrink(int n){
width-=n;
height=(int)(width/2);
}
public void display(Graphics g){
g.setColor(Color.green);
g.fillRect(xCoord,yCoord,width,height);
g.drawRect(xCoord,yCoord,width,height);
g.setColor(Color.black);
g.fillOval(xCoord,yCoord-height/3,height/3,width/6);

}

}