I am kind of new to Java and I am trying some stuff with swing.
class CustomListSelectionListener implements ListSelectionListener {
public void valueChanged (ListSelectionEvent e)
{
//All this listener does is to return the NAME of the selected connection to the static method gotocategories.
JList lsm = (JList)e.getSource();
Home.goToCategories((String)lsm.getSelectedValue());
}
problem is, the listener is a class, so basically if I call a static method from the "home class" I need to make all the variables I have to use in the "goToCategories" function static.
public static void goToCategories(String collectionname)
{
Statement stmt;
try
{
stmt = privconn.createStatement();
//Getting the collection ID;
String firststmt = "SELECT * FROM collection WHERE Name='"+collectionname+"' AND User_ID = "+userID+"";
ResultSet rs = stmt.executeQuery(firststmt);
rs.next();
int id = rs.getInt("ID");
JOptionPane.showMessageDialog(null, id);
} catch(Exception E)
{
E.printStackTrace();
}
}
This code works , but I think I am creating a lot of static variables and I am not sure that's the best way to do it. Of course as soon as I try and remove the static it'll say "Cannot make static reference to non-static field ..."