Java 2 Compatibility Package

At this time, some platforms--notably Linux and the Macintosh--do not yet have a stable platform for Java 2 programming. For that reason, I supply a compatibility package that enables students to compile the programs in Computing Concepts with Java 2 Essentials with a Java 1.1 compatible compiler. (Note: Java 1.0 is not supported. Note further that Microsoft J++ 1.1 implements Java 1.0 only.)

To use the compatibility package, students must take the following steps.

  1. Download the compatibility package and unzip.

    (Don't have ZIP on your platform? Just use jar: jar xvf java2compatibility.zip)

  2. Place the file java2compatibility.jar into a convenient directory, for example c:\ccj2book\java2compatibility.jar.
  3. Add java2compatibility.jar to their class path. This depends on the compiler. For the JDK, students would need to modify the CLASSPATH environment variable to contain They will likely need help with this step.
  4. Change import directives to
    import com.horstmann.ccj.java2compatibility.ClassName;
    for Java 2 classes such as Graphics2D, JFrame, and so on. See below for a complete list.
  5. In paint and paintComponent methods, change the cast
    Graphics2D g2 = (Graphics2D)g;
    to a constructor call
    Graphics2D g2 = new Graphics2D(g);
    This is unfortunately unavoidable since Java 1.1 doesn't supply a Graphics2D object when calling paint.
  6. Make the following changes:
    Class Change from Java 2 to Java 1.1
    Component c.getWidth() c.getSize().width
    Component c.getHeight() c.getSize().height
    Double Double.parseDouble(x) new Double(x).doubleValue()
    Float Float.parseFloat(x) new Float(x).floatValue()
    Math Math.toRadians(x) x * Math.PI / 180
    Random r.nextInt(n) r.nextInt() % n
    Vector v.get(i) v.elementAt(i)
    Vector v.add(x) v.addElement(x)

The following classes and interfaces are supported:

Graphics2D
FontRenderContext
TextLayout
RectangularShape
Ellipse2D.Double
Rectangle2D.Double
Point2D.Double
Line2D.Double

JFrame
JPanel
JButton
JTextField
JTextArea
JMenuBar
JMenu
JMenuItem
JCheckBox
JRadioButton
JComboBox
JOptionPane
JFileChooser 

Note: If your environment supports Java 1.1 with Swing, then you only need the first few graphics classes from the Java 2 support package. In that case, tell your students to keep the javax.swing classes and place the Swing library on the class path.

Limitations: