Java Reference
In-Depth Information
Figure 3.6. The RocketTable class adapts the TableModel interface to the Rocket
class from the Oozinoz domain.
The RocketTable class has to subclass AbstractTableModel because
AbstractTableModel is a class, not an interface. Whenever the interface you are adapting
to is supported with an abstract class, you must use an object adapter. In this example, though,
there is a second reason you cannot use a class adapter. A RocketTable is not a kind or a
subtype of Rocket . When an adapter class must draw on information from more than one
object, you have to implement the adapter as an object adapter.
When you create the RocketTable class, you can easily display information about rockets
in a Swing JTable object, as Figure 3.7 shows. To create the application that Figure 3.7
shows, you have to develop the RocketTable class and before writing an application that
shows the table:
package com.oozinoz.applications;
import javax.swing.table.*;
import com.oozinoz.fireworks.*;
public class RocketTable extends AbstractTableModel
{
protected Rocket[] rockets;
protected String[] columnNames =
new String[] { "Name", "Price", "Apogee" };
Search WWH ::




Custom Search