Package edu.hws.jcm.draw
Class Graph1D
java.lang.Object
edu.hws.jcm.draw.Drawable
edu.hws.jcm.draw.Graph1D
- All Implemented Interfaces:
Computable
,Serializable
A Graph1D represents the graph of a function of one variable, to be
displayed in a given CoordinateRect. A Graph1D is a Computable.
The data for the graph is recomputed when its compute() method is
called. It will also be recomputed, before it is drawn, if the
coordinate rect has changed in some way.
- See Also:
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
compute()
Recompute data for the graph and make sure that the area of the display canvas that shows the graph is redrawn.void
Draw the graph (possibly recomputing the data if the CoordinateRect has changed).getColor()
Get the color that is used to draw the graph.Get the (possibly null) function whose graph is drawn.void
Set the color to be used for drawing the graph.void
Set the function to be graphed.Methods inherited from class edu.hws.jcm.draw.Drawable
getVisible, needsRedraw, setOwnerData, setVisible
-
Constructor Details
-
Graph1D
public Graph1D()Create a Graph1D with no function to graph. One can be set later with setFunction(); -
Graph1D
Create a graph of the specified function.- Parameters:
func
- The function to be graphed. If func is null, nothing is drawn. If func is non-null, it must be a function of one variable.
-
-
Method Details
-
setColor
Set the color to be used for drawing the graph. The default color is magenta. -
getColor
Get the color that is used to draw the graph. -
setFunction
Set the function to be graphed. If it is null, nothing is drawn. If it is non-null, it must be a function of one variable, or an error will occur. -
getFunction
Get the (possibly null) function whose graph is drawn. -
compute
public void compute()Recompute data for the graph and make sure that the area of the display canvas that shows the graph is redrawn. This method is ordinarily called by a Controller.- Specified by:
compute
in interfaceComputable
-
draw
Draw the graph (possibly recomputing the data if the CoordinateRect has changed). This is not usually called directly.- Specified by:
draw
in classDrawable
- Parameters:
g
- The graphics context in which the Drawble is to be drawn. (The drawing can change the color in g, but should not permanently change font, painting mode, etc. Thus, every drawable is responsible for setting the color it wants to use.)coordsChanged
- Indicates whether the CoordinateRect has changed.
-