Rabu, 21 Desember 2011

JDBC_Kelas RegionTableModel

package JDBC;

import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;


public class RegionsTableModel extends AbstractTableModel {

    String columNames[] = {"Nomor", "Regions"};
    ArrayList data;

    public RegionsTableModel(String keyword) throws SQLException {
        data = Regions.searchRegions(keyword);
    }

    public int getRowCount() {
        return data.size();
    }

    public int getColumnCount() {
        return columNames.length;
    }

    @Override
    public String getColumnName(int col) {
        return columNames[col];
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Regions temp = (Regions) data.get(rowIndex);
        if (columnIndex == 0) {
            return temp.getRegionId();
        } else {
            return temp.getRegionName();
        }
    }

    @Override
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

    public static void main(String[] args) throws SQLException {
        RegionsTableModel test = new RegionsTableModel("Asia");
        System.out.println("nama :" + test.getValueAt(0, 1));
    }

}

Tidak ada komentar:

Posting Komentar