could anyone conclude that!
CODE
public interface Drawing {
void setOrigin( int x0, int y0);
void Draw(java.awt.Graphics g);
void setX(int x);
void setY(int y);
int getX();
int getY();
}
public abstract class shape implements Drawing
protected int x0=0,y0=0;
protected int x=0,y=0;
public shape(int x, int y){
this(0,0,x,y);
}
public shape(int x0,int y0, int x, int y) {
this.x0=x0;
this.y0=y0;
this.x=x;
this.y=y;
}
public void setOrigin(int x0, int y0) {
this.x0=x0;
this.y0=y0;
}
public void setY(int y) {
this.y=y;
}
public void setX(int x) {
this.x=x;
}
public int getY() {
return y;
}
public int getX() {
return x;
}
public abstract void Draw(java.awt.Graphics g);
}
public class Circle extends shape{
private int radius;
public Circle(int x, int y, int radius ) {
super(x,y);
this.radius=radius;
}
public void setRadius(int r){
if(r >=0 )radius=r;
}
public void Draw(java.awt.Graphics g) {
g.drawOval(x+x0-radius,y0-y-radius, radius*2, radius*2);
}
}
public class Rectangle extends shape{
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);
}
}
import javax.swing.JApplet;
import java.awt.Graphics;
import java.awt.Color;
public class XYPlane extends JPanel {
private XYShape[] dr;
private Color BackColor=Color.WHITE;
private int count=0;
public void init(){
dr=new XYShape[100];
}
public void Add(XYShape d){
if(d!=null){
dr[count]=d;
count++;
}
}
public void setBackColor(Color c){
if(c!=null)BackColor=c;
}
public void DrawAxis(Graphics g){
g.setColor(Color.BLACK);
g.drawLine(0, getHeight()/2, getWidth(), getHeight()/2 );
g.drawLine( getWidth()/2 , 0, getWidth()/2, getHeight());
}
public void paint(Graphics g){
Color c=g.getColor();
g.setColor(BackColor);
g.fillRect(0,0,getWidth(), getHeight());
g.setColorŠ;
DrawAxis(g);
int i=0;
while(i < count ){
dr[i].setOrigin(getWidth()/2 ,getHeight()/2);
dr[i].Draw(g);
i++;
}
}
}