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.
- Download the compatibility package
and unzip.
(Don't have ZIP on your platform? Just use jar: jar
xvf java2compatibility.zip)
- Place the file java2compatibility.jar into a convenient
directory, for example c:\ccj2book\java2compatibility.jar.
- 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
- The standard Java classes (e.g. c:\jdk1.1.6\lib\classes.zip)
- The current directory (.)
- The Java 2 compatibility package (e.g. c:\ccj2book\java2compatibility.jar)
They will likely need help with this step.
- 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.
- 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.
- 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:
- Only the methods that are actually used in the book are supported.
Please let me know if you want me to support additional methods for
exercises.
- The JSlider class is not supported. It is used in a single
example at the end of chapter 12 which you would need to omit.
- The EtchedBorder and TitledBorder classes are not
supported. They are used in a single example in chapter 12, and you
would have to tell your students to omit this decorative element.
- The java.awt.Color constructor in Java 1.1 does not take
float constructors. Programs using color must be changed to
use integer coordinates. This affects one program in chapter 4.
- The java.awt.Rectangle class in Java 1.1 does not extend
the RectangularShape class. Therefore, the unit converter
cannot be used to convert rectangles. Remedy: Modify the program to use
Rectangle2D.Double. This affects one program in chapter 4.
- Java 1.1 does not support the Comparable interface. Remedy:
Restrict the exposition to arrays and trees of String objects.
This affects two programs in chapters 15 and 16.
- Java 1.1 does not support the LinkedList class. Remedy: Use
the class developed in chapter 16. This affects one program in chapter
16.