import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Stroke;
import java.awt.geom.Ellipse2D;import javax.swing.JFrame;
import javax.swing.JPanel;/*
 * Created on 2007-6-9
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 *//**
 * @author yopeng
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class BallApp extends JFrame {
   public BallApp(String title){
      super(title);
      this.setSize(600,450);
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      this.add(new BallPanel());
      this.setVisible(true);
   }
public class BallPanel extends JPanel{
private final int INIT_X =75;
private final int INIT_Y =75;
private final int DIAMETER =60;
private SmartEllipse _ball;
   public BallPanel(){
      super ();
      _ball = new SmartEllipse(Color.red);
      this.setBackground(Color.white);
      _ball.setLocation(INIT_X,INIT_Y);
      _ball.setSize(DIAMETER,DIAMETER);
   }
   public void paintComponet(Graphics aBrush){
       super.paintComponent(aBrush);
       Graphics2D betterBrush= (Graphics2D) aBrush;
       _ball.fill(betterBrush);
    }
 }
public class SmartEllipse extends Ellipse2D.Double{
   private Color _borderColor,_fillColor;
   private int _rotation;
   private final int STROKE_WIDTH = 2;
   
   public void draw(Graphics2D aBrush){
      Color savedColor = aBrush.getColor();
      aBrush.setColor(_borderColor);
      Stroke savedStroke = aBrush.getStroke();
      aBrush.setStroke(new BasicStroke(STROKE_WIDTH));
      aBrush.draw(this);
      aBrush.setStroke(savedStroke);
      aBrush.setColor(savedColor);
   }
   public void fill(Graphics2D aBetterBrush){
      Color savedColor = aBetterBrush.getColor();
      aBetterBrush.fill(this);
      aBetterBrush.setColor(_fillColor);
   }
   public SmartEllipse(Color aColor){
      super();
      _borderColor=aColor;
      _fillColor=aColor;
      _rotation =0;
   } 
   public void setBorderColor(Color aColor){
    _borderColor=aColor;
   }
   public void setFillColor(Color aColor){
    _fillColor=aColor;
   }
   public void setColor(Color aColor){
    _borderColor=aColor;
  _fillColor=aColor;
   }
   public void setRotation(int aRotation){
    _rotation =aRotation;
  }
   public void setLocation(double x,double y){
      this.setFrame(x,y,this.getWidth(),this.getHeight()); 
   }
   public void setSize(int aWidth,int aHeight){
    this.setFrame(this.getX(),this.getY(),aWidth,aHeight); 
   }
   public void move(int aChangeInX, int aChangeInY){
      this.setFrame((int)this.getX()+aChangeInX,
               (int)this.getY()+aChangeInY,
this.getWidth(),this.getHeight());
   }
} public static void main(String[] args) {
BallApp app = new BallApp("ball!");
}
}