Listeners, such as the one defined in
Segment 1007, are connected to
list-selection model inside the table, which you obtain using the
getSelectionModel
method, as illustrated in the following,
RowMovieTableApplication
subclass of the
MovieTableApplication
class. All that the subclass definition does
is to define a zero-parameter constructor that connects
the table to an instance of the MovieRowSelectionListener
class
defined in Segment 1007.
import javax.swing.*; public class RowMovieTableApplication extends MovieTableApplication { public RowMovieTableApplication () { ListSelectionModel lsm = getRatingTable().getSelectionModel(); lsm.addListSelectionListener(new MovieRowSelectionListener(this)); } public static void main (String argv []) { JFrame frame = new JFrame("Movie Data Table"); frame.getContentPane().add("Center", new RowMovieTableApplication()); frame.setSize(750, 210); frame.addWindowListener(new ApplicationClosingWindowListener()); frame.show(); } }