Java Reference
In-Depth Information
public RocketTable(Rocket[] rockets)
{
this.rockets = rockets;
}
public int getColumnCount()
{
// challenge!
}
public String getColumnName(int i)
{
// challenge!
}
public int getRowCount()
{
// challenge!
}
public Object getValueAt(int row, int col)
{
// challenge!
}
}
Figure 3.7. This GUI displays an instance of
JTable
fueled with rocket data.
CHALLENGE 3.2
Fill in the code for the
RocketTable
methods that adapt an array of
Rocket
objects to serve as a
TableModel
.
To launch the display that Figure 3.7 shows, you can create a couple of example
Rocket
objects, place them in an array, construct an instance of
RocketTable
from the array, and
use Swing classes to display the table. The
ShowRocketTable
class provides an example: