import javax.swing.*;
import quick.dbtable.*;
import java.sql.*;
public class QuickTableFrame extends JFrame
{
public QuickTableFrame()
{
//set Frame properties
setSize(300,200);
setVisible(true);
//create master & detail tables
quick.dbtable.DBTable masterTable = new quick.dbtable.DBTable();
quick.dbtable.DBTable detailTable = new quick.dbtable.DBTable();
//add to frame
getContentPane().add(masterTable, BorderLayout.CENTER);
getContentPane().add(detailTable, BorderLayout.SOUTH);
//set the database driver to be used, we are using jdbc-odbc driver
masterTable.setDatabaseDriver("sun.jdbc.odbc.JdbcOdbcDriver");
/*
set the jdbc url,"quicktabledemo" is the data source we have created
for the database
*/
masterTable.setJdbcUrl("jdbc:odbc:quicktabledemo");
// set the select statement which should be used by the table
masterTable.setSelectSql("select * from employee");
//to create the navigation bars for the table
masterTable.createControlPanel();
//listen for any row changes in the master table
//once a new row is selected, fill the detail table with corresponding related information
masterTable.addDBTableEvenetListener(new DBTableEventListener()
{
public void afterRowSelectionChange(int fromRow, int toRow)
{
//get the primary key value from master table
//and query the detail data with the primary key
detailTable.setSelectSql("select * from employee_details where emp_id=" + masterTable.getValueAt(toRow, 1));
try{
detailTable.refresh();
}catch(Exception ex)
{
ex.printStackTrace();
}
}
};
try
{
//connect to database & create a connection
masterTable.connectDatabase();
//assign this database connection to detail table also.
detailTable.setConnection(masterTable.getConnection());
//fetch the data from database to fill the table
masterTable.refresh();
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
//create a new table frame
QuickTableFrame myframe = new QuickTableFrame();
}
}