In a subclass of the MovieTableApplication
class, you connect your
new listener to the rating-table model. All the subclass definition
does is to call addListSelectionListener
on the appropriate target with
an instance of the MovieTableCellListener
class defined in
Segment 1011 as an ordinary argument.
Note that you must not have row selection turned on, as row selection would
interfere with cell editing. Accordingly, you should use the
RatingTable
definition provided in Segment 1000.
import javax.swing.*; import javax.swing.table.*; public class CellMovieTableApplication extends MovieTableApplication { public CellMovieTableApplication () { TableModel tm = getRatingTable().getModel(); tm.addTableModelListener(new MovieTableCellListener(this)); } public static void main (String argv []) { JFrame frame = new JFrame("Movie Data Table"); frame.getContentPane().add("Center", new CellMovieTableApplication()); frame.setSize(750, 210); frame.addWindowListener(new ApplicationClosingWindowListener()); frame.show(); } }