Jacob
Nov 12th, 2002, 09:54 AM
Hi.
I use the constructor to get the information from the database, but it doesn't complie. Here is my code for the constructor.
=============================================
public getData() {
Connection c = DriverManager.getConnection_("jdbc:odbc:GradeData");
ResultSet r = c.createStatement().executeQuery("SELECT_ ProductID, ProductName FROM Inventory");
ResultSetMetaData rsmd = r.getMetaData();
int i = 0;
while (r.next()) {
strItemNo_Descript[i] = r.getInt("ProductID") +"\t"+ _r.getString("ProductName");
++i;
}
c.close();
//Set all the elements of JFrame
JPanel content = new JPanel();
labelInstruct = new JLabel("Please select the item no");
content.add(labelInstruct);
itemList = new JList(strItemNo_Descript);
itemList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
itemList.setVisibleRowCount(8);
// ======== Here is the problem.===========
itemList.addListSelectionListener(this);
itemPane = new JScrollPane(itemList);
content.add(itemPane);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
} );
}
==============================================
The code above has the following error:
addListSelectionListener(javax.swing.event.ListSelectionListener)_ in javax.swing.JList cannot be applied to (getData)_itemList.addListSelectionListener(this);
Would you tell me how to fix this?
Thank You Very Much.
Jacob
I use the constructor to get the information from the database, but it doesn't complie. Here is my code for the constructor.
=============================================
public getData() {
Connection c = DriverManager.getConnection_("jdbc:odbc:GradeData");
ResultSet r = c.createStatement().executeQuery("SELECT_ ProductID, ProductName FROM Inventory");
ResultSetMetaData rsmd = r.getMetaData();
int i = 0;
while (r.next()) {
strItemNo_Descript[i] = r.getInt("ProductID") +"\t"+ _r.getString("ProductName");
++i;
}
c.close();
//Set all the elements of JFrame
JPanel content = new JPanel();
labelInstruct = new JLabel("Please select the item no");
content.add(labelInstruct);
itemList = new JList(strItemNo_Descript);
itemList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
itemList.setVisibleRowCount(8);
// ======== Here is the problem.===========
itemList.addListSelectionListener(this);
itemPane = new JScrollPane(itemList);
content.add(itemPane);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
} );
}
==============================================
The code above has the following error:
addListSelectionListener(javax.swing.event.ListSelectionListener)_ in javax.swing.JList cannot be applied to (getData)_itemList.addListSelectionListener(this);
Would you tell me how to fix this?
Thank You Very Much.
Jacob