Let's Do It! - Java Classes and Discussion

Alexander Bogomolny

For instructions on using Java source files from JOMA, see the How-to page.

  1. View the source for CubicSpline.java
  2. View the source for Tridiagonal.java
  3. View the source for MMover.java
  4. View the source for MMoveable.java
  5. View the source for MPoint.java
  6. View the source for VPoint.java
  7. View the source for Scale.java
  8. View the source for SplineTest.java
  9. View the source for SplineTestCanvas.java
  10. View the source for SplineTestPanel.java

  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:


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:


and there is no limit on how many various interfaces a class may implement. For example,   extends an awt class   while implementing two Java 1.1 interfaces:   and  .   is the simplest class I could think of that implements the   interface. It's a draggable point which is shown (if desirable) by a small circle.   extends  . It differs from   in three respects. First, it may only be dragged up and down. Second, it stores information (in the form of two   attributes:   and  ) 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.  s are used to convert between the two systems. Third,   is more lax than   in its response to a dragging initiative.   responds to a mouse pressed event when the cursor is a small distance away.   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   and   extremely convenient. Each   object "knows" by means of its   method when dragging is about to start. All draggable objects are reported to a   object through its   method. One (as in the   example) or more   objects are created per screen estate areas (usually,  es in awt) to manage   objects.   methods are invoked on three occasions:


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,  , has a built-in flaw, a violation of basic OO principles. Can you find it?