Welcome to Dream.In.Code
Become a Java Expert!

Join 149,523 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,438 people online right now. Registration is fast and FREE... Join Now!




drawing shapes

 
Reply to this topicStart new topic

drawing shapes

aluur
19 May, 2007 - 08:47 AM
Post #1

New D.I.C Head
*

Joined: 16 Apr, 2007
Posts: 8


My Contributions
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++;
        }

        
   }
    
}

User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Drawing Shapes
20 May, 2007 - 12:40 PM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,868



Thanked: 53 times
Dream Kudos: 550
My Contributions
what exactly is your question?
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 08:43PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month