tailieunhanh - Ivor Horton’s Beginning Java 2, JDK 5 Edition phần 10

Bạn thường sẽ cần phải lặp lại một khối thông tin ở những nơi khác nhau trong một DTD. Một thực thể tham số xác định một khối văn bản phân tích cú pháp bởi một tên mà bạn có thể sử dụng để chèn văn bản tại các địa điểm khác nhau trong một DTD. Lưu ý rằng các thực thể tham số để sử dụng chỉ trong vòng một DTD. | Talking to Databases array you store a reference to it in dataRows. After all the rows from the resultset have been stored you call the fireTableChanged method that the ResultsModel class inherits from the base class. This method notifies all listeners for the JTable object for this model that the model has changed so the JTable object should redraw itself from scratch. The argument to the fireTableChanged method is a reference to an object of type TableModelEvent that you can use to record the parts of the model that have changed and this is passed to the listeners. You pass a null here as you want to invalidate the whole table. The method to return the number of columns is now very easy to implement public int getColumnCount return The column count is the number of elements in the columnNames array. Supplying the row count is just as easy public int getRowCount return dataRows null 0 The number of rows corresponds to the size of the Vector object dataRows. You check to verify that the value of the dataRows vector is not null to ensure that the initialization of the InteractiveSQL GUI can take place even when the vector has not been initialized. The next method you need to define provides access to the data values. You can implement this as follows public String getValueAt int row int column return row column The elementAt method returns the element in the Vector object at the position specified by the argument. This will be a reference to an array of type String so you just index this with the value of the column parameter to select the element to be returned. The last method you must add to the class is getColumnName which will return the column name given a column index. You can implement this as public String getColumnName int column return columnNames column null No Name columnNames column You take the precaution here of dealing with a null column name by supplying a default column name in this case. 1321 .