package part2;
import java.awt.Color;
import java.awt.Point;
public abstract class Shape {
protected Color color;
public Shape(Color color) {
this.color = color;
}
public Color getColor() {
return this.color;
}
public void setColor(Color c) {
this.color = c;
}
abstract double getArea();
abstract double getPerimeter();
abstract void translate(Point p);
}
(x,y)
coordinate space,
specified in integer precision.(x,y)
coordinate space,
specified in integer precision.Color
class is used to encapsulate colors in the default
sRGB color space or colors in arbitrary color spaces identified by a
ColorSpace
. Every color has an implicit alpha value of 1.0 or
an explicit one provided in the constructor. The alpha value
defines the transparency of a color and can be represented by
a float value in the range 0.0 - 1.0 or 0 - 255.
An alpha value of 1.0 or 255 means that the color is completely
opaque and an alpha value of 0 or 0.0 means that the color is
completely transparent.
When constructing a Color
with an explicit alpha or
getting the color/alpha components of a Color
, the color
components are never premultiplied by the alpha component.
Color
class is used to encapsulate colors in the default
sRGB color space or colors in arbitrary color spaces identified by a
ColorSpace
. Every color has an implicit alpha value of 1.0 or
an explicit one provided in the constructor. The alpha value
defines the transparency of a color and can be represented by
a float value in the range 0.0 - 1.0 or 0 - 255.
An alpha value of 1.0 or 255 means that the color is completely
opaque and an alpha value of 0 or 0.0 means that the color is
completely transparent.
When constructing a Color
with an explicit alpha or
getting the color/alpha components of a Color
, the color
components are never premultiplied by the alpha component.
The default color space for the Java 2D(tm) API is sRGB, a proposed standard RGB color space. For further information on sRGB, see http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html .
The abstract
keyword is used to declare that this is an abstract method.
The abstract
keyword is used to declare that this is an abstract method.
These are the abstract class's concrete methods. They have method bodies (or implementations). Subclasses can override these methods, but they don't have to. They can inherit these methods if they want.
These are the abstract class's concrete methods. They have method bodies (or implementations). Subclasses can override these methods, but they don't have to. They can inherit these methods if they want.
These are the abstract class's abstract methods. They do not have method bodies (or implementations). Subclasses must override these methods. They cannot inherit these methods, since there's nothing to inherit.
These are the abstract class's abstract methods. They do not have method bodies (or implementations). Subclasses must override these methods. They cannot inherit these methods, since there's nothing to inherit.
The protected
keyword is used to declare that this instance variable is
visible to subclasses of this class. If we had used private
instead,
the variable would not be visible to subclasses. In that case, they would
need to use the getColor
and setColor
methods to access the variable.
The protected
keyword is used to declare that this instance variable is
visible to subclasses of this class. If we had used private
instead,
the variable would not be visible to subclasses. In that case, they would
need to use the getColor
and setColor
methods to access the variable.
Even though we can't create a Shape
object, we still have a constructor
in this class. This constructor's job is to initialize the instance variables
that are declared at this level, namely color
.
Even though we can't create a Shape
object, we still have a constructor
in this class. This constructor's job is to initialize the instance variables
that are declared at this level, namely color
.
The abstract
keyword is used to declare that this is an abstract class.
This does two things:
The abstract
keyword is used to declare that this is an abstract class.
This does two things:
Abstract classes can have instance variables. Here, all Shape
s have a
color
, so we put this instance variable in this abstract class. All
subclasses of Shape
will inherit this instance variable.
Abstract classes can have instance variables. Here, all Shape
s have a
color
, so we put this instance variable in this abstract class. All
subclasses of Shape
will inherit this instance variable.