java.lang.Objectobjectdraw.ObjectDrawObject
objectdraw.ObjectDrawShape
objectdraw.ObjectDrawRectangularShape
objectdraw.FramedRect
fluids.FluidContainer
fluids.Tank
public class Tank
A Tank
represents a container that can fill up with liquid. The amount of liquid can
be measured in two ways: the volume, in gallons, and the water level, the y coordinate on the screen
of the surface of the liquid. For completeness, it permits the volume to be negative, but negative
volume shows up in a different color (red, by default) to show that it is negative.
Field Summary |
---|
Fields inherited from interface objectdraw.DrawableStrokeInterface |
---|
CLICK_SIZE, DEFAULT_STROKE |
Constructor Summary | |
---|---|
Tank(String name,
Background background)
Create a new Tank . |
Method Summary | |
---|---|
double |
getCapacity()
Get the maximum volume that this tank can hold |
double |
getVolume()
Get the volume of liquid present in this tank. |
double |
getWaterLevel()
Get the water level in this tank. |
void |
setVolume(double v)
Set the volume of liquid in this Tank . |
void |
setWaterLevel(double level)
Set the water level of this tank. |
Methods inherited from class fluids.FluidContainer |
---|
contains, getBackground, getNegativeColor, removeFromCanvas, setColor, setNegativeColor |
Methods inherited from class objectdraw.FramedRect |
---|
addToCanvas, getCanvas, getColor, getDoubleHeight, getDoubleWidth, getDoubleX, getDoubleY, getHeight, getLineWidth, getLocation, getStroke, getWidth, getX, getY, hide, isHidden, makeShape, move, moveTo, moveTo, overlaps, sendBackward, sendForward, sendToBack, sendToFront, setHeight, setLineWidth, setSize, setStroke, setWidth, show, toString |
Methods inherited from class objectdraw.ObjectDrawRectangularShape |
---|
getBounds |
Methods inherited from class objectdraw.ObjectDrawShape |
---|
clearCanvas, draw, draw, getDrawables, getShape, removeCanvas, setMyShape, update |
Methods inherited from class objectdraw.ObjectDrawObject |
---|
deferUpdates, depend, runUpdates, undepend |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface objectdraw.DrawableInterface |
---|
draw, getShape |
Constructor Detail |
---|
public Tank(String name, Background background)
Tank
. The dimensions of the tank will be set to reflect the area of
the image where this tank's water may appear, and contains() will return true only for points
within the liquid area of this tank.
name
- Name of .png file to load from the modelbackground
- Background
which knows which model to load the image file from,
and on which the water in this Tank
will be drawn.Method Detail |
---|
public double getCapacity()
public double getVolume()
public double getWaterLevel()
tank.getY()
(where volume = capacity)
and tank.getY() + tank.getHeight()
(where volume = 0), assuming the volume is
positive. If the volume is negative, a water level below the bottom of the tank will be
returned, calculated as if the tank were mirrored over its bottom edge.
public void setVolume(double v)
Tank
. If the volume is greater than the capacity,
or less than the negative of the capacity, the tank may overflow into the background.
v
- new volume, in gallonspublic void setWaterLevel(double level)
level
- New water level