Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Latest commit e916d17 Mar 26, 2019 History
1 contributor

Users who have contributed to this file

/**
* Chapter 9: SmartEllipse.java
* Adds capabilities to the Java2D.Double ellipse.
* Same as the class defined in Chapter 7.
*/
public class SmartEllipse extends java.awt.geom.Ellipse2D.Double {
private java.awt.Color _borderColor, _fillColor;
private double _rotation;
private final int STROKE_WIDTH = 2;
public SmartEllipse(java.awt.Color aColor){
_borderColor = aColor;
_fillColor = aColor; // solid color to start
_rotation = 0;
}
// methods not provided by Java
public void setBorderColor (java.awt.Color aColor) {
_borderColor = aColor;
}
public void setFillColor (java.awt.Color aColor) {
_fillColor = aColor;
}
public void setColor (java.awt.Color aColor) {
_borderColor = aColor;
_fillColor = aColor;
}
public void setRotation (double aRotation) {
_rotation = aRotation;
}
// more readable versions of methods provided by Java
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);
}
// not provided by Java
public void fill (java.awt.Graphics2D aBrush){
java.awt.Color oldColor = aBrush.getColor();
aBrush.setColor(_fillColor);
aBrush.rotate(_rotation, this.getX()+(this.getWidth()/2), this.getY()+(this.getHeight()/2));
aBrush.fill(this);
aBrush.rotate(-_rotation, this.getX()+(this.getWidth()/2), this.getY()+(this.getHeight()/2));
aBrush.setColor(oldColor);
}
public void draw (java.awt.Graphics2D aBrush) {
java.awt.Color oldColor = aBrush.getColor();
aBrush.setColor(_borderColor);
java.awt.Stroke oldStroke = aBrush.getStroke();
aBrush.setStroke(new java.awt.BasicStroke(STROKE_WIDTH));
aBrush.rotate(_rotation, this.getX()+(this.getWidth()/2), this.getY()+(this.getHeight()/2));
aBrush.draw(this);
aBrush.rotate(-_rotation, this.getX()+(this.getWidth()/2), this.getY()+(this.getHeight()/2));
aBrush.setStroke(oldStroke);
aBrush.setColor(oldColor);
}
}