posted 22 years ago
I've been twisting on this problem and I need help. My program has a class with a JFrame. This JFrame class is big with many JTabbedPanes. I also have many classes that extend JPanel. So,
the class with the JFrame implements new instances of the JPanels. My problem is one of the JPanels uses JButtons. The number of JButtons is determined by the number of records returned in a recordset. I'm having trouble attaching an ActionListener to the JButtons Example:
class SomeGUI extends JPanel {
... some GUI code
while(ResultSet.next()) {
button = new JButton("Edit");
... more stuff
}
}
class MasterFrame extends JFrame {
SomeGUI guiONE = new SomeGUI();
JPanel masterPanel = new JPanel();
masterPanel.add(guiONE);
masterPanel.add(guiTWO); // I didn't show guiTWO above but
// you get the idea.
this.getContentPane().add(masterPanel);
}
The part that doesn't work is when I try to add an ActionListener to the JButtons in SomeGUI. If I add an inner class to SomeGUI, I don't see how I'll be able to get that inner class to work with my instance of MasterFrame. If I write an inner class in MasterFrame, I don't see how to add a listener to each instance of Button(because button is created many times in the while loop).
I've hit a wall. Please Help.
Ray