For instructions on using Java source files from JOMA, see the How-to page.
- View the source for CubicSpline.java
- View the source for Tridiagonal.java
- View the source for MMover.java
- View the source for MMoveable.java
- View the source for MPoint.java
- View the source for VPoint.java
- View the source for Scale.java
- View the source for SplineTest.java
- View the source for SplineTestCanvas.java
- View the source for SplineTestPanel.java
MMoveable is a Java interface which is a sort of abstract class whose methods have no bodies and whose attributes are necessarily final. Interfaces are the Java answer to the classical question of multiple inheritance. Formally speaking, a Java class cannot be derived from 2 or more other classes. When class A is derived from class B, it must be declared in the following manner:
class A extends B
It would be a mistake to extend a class from two or more classes. When class A derives from an interface B, the declaration is different:
class A implements B
and there is no limit on how many various interfaces a class may implement. For example,
SplineTestCanvas extends an awt class
Canvas while implementing two Java 1.1 interfaces:
MPoint is the simplest class I could think of that implements the
MMoveable interface. It's a draggable point which is shown (if desirable) by a small circle.
MPoint. It differs from
MPoint in three respects. First, it may only be dragged up and down. Second, it stores information (in the form of two
YScale) about an additional coordinate system. Screen coordinates are a natural choice when a point must be dragged around. For numerical computations, "real world" coordinates are more convenient.
Scales are used to convert between the two systems. Third,
VPoint is more lax than
MPoint in its response to a dragging initiative.
MPoint responds to a mouse pressed event when the cursor is a small distance away.
VPoint responds to a mouse press when the cursor is at a prescribed distance away both vertically and horizontally. Distances in the two directions are not necessarily the same. The idea here was to insure responsiveness to the cursor movements while avoiding unnecessary accidental proliferation of interpolation points.
I found the combination of
MMoveable extremely convenient. Each
MMoveable object "knows" by means of its
IsHit method when dragging is about to start. All draggable objects are reported to a
MMover object through its
AddMoveable method. One (as in the
SplineTest example) or more
MMover objects are created per screen estate areas (usually,
Canvases in awt) to manage
MMover methods are invoked on three occasions:
public void mousePressed(MouseEvent event)
if (Mover.IsHit(event.getX(), event.getY()))
public void mouseReleased(MouseEvent event)
public void mouseDragged(MouseEvent event)
I plan to create more applets that use the above classes. Meanwhile, comments, friendly critique, and suggestions are welcome. From the programming perspective, the nicest applet only deserves a place in The Applet Book if it's been designed according to simple principles and coded following simple guidelines. I know nothing more intuitive and natural than the object-oriented paradigm. As a hook for a possible discussion on OOD (OO design) and OOP (OO Programming), one of the classes,
VPoint, has a built-in flaw, a violation of basic OO principles. Can you find it?