i want to draw square when button named square clicked, i preapared that ;
rectangle extends shape, and square extends rectangle . it seems true when compiled but i cannot draw a square i can draw a rectangle.
CODE
public class Rectangle extends XYShape {
private int height,width;
public Rectangle(int x,int y) {
super(x,y);
}
public Rectangle(int x ,int y,int width ,int height){
super(0, 0,x,y);
setWidth(width);
setHeight(height);
}
public void setWidth(int w){
if( w > 0 )width=w;
}
public void setHeight(int h){
if(h > 0)height=h;
}
public int getWidth(){return width;}
public int getHeight(){return height;}
public void Draw(java.awt.Graphics g) {
g.drawRect(x0+x, y0-y, width,height);
}
}
public class Square extends Rectangle{
private int side;
public Square(int x ,int y ) {
super(x,y);
}
public Square(int x, int y,int side){
super(side,side);
}
public int getSide() {
return getWidth(); }
public void setSide(int side) {
super.setWidth(side);
super.setHeight(side);
}
public void setWidth(int width) {
this.setSide(side); }
public void setHeight(int width) {
this.setSide(side); }
}
whats the problem with me i couldnt understand exactly, i jsut wonder wheter my main class or square class