Down towards the bottom of my code where I open up a new JFrame
(balanceFrame
or valueFrame
), a new frame opens up with one of those frames when a user right clicks that menu option.
However, after closing the new balanceFrame
or valueFrame
that pops up, and you open up another balance
/valueFrame
, two open up. After you close those two and open another, three open up. Any idea on how to stop this? It seems like my programs remembering past values for the variable 'value' and opening up multiple windows.
table.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
System.out.println("Pressed");
}
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
JTable source = (JTable)e.getSource();
int row = source.rowAtPoint( e.getPoint() );
int column = source.columnAtPoint( e.getPoint() );
String value = table.getModel().getValueAt(row, column).toString();
if (! source.isRowSelected(row))
source.changeSelection(row, column, false, false);
popup.show(e.getComponent(), e.getX(), e.getY());
menuItemBalanceSheet.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
balanceFrame = new BalanceFrame("BalanceSheet", value);
} catch (Exception e1) {
e1.printStackTrace();
}
balanceFrame.setSize(1200, 600);
balanceFrame.setVisible(true);
balanceFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
});
menuItemCompanyValue.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
valueFrame = new ValueFrame("Company Value", value);
} catch (Exception e1) {
e1.printStackTrace();
}
valueFrame.setSize(1200, 600);
valueFrame.setVisible(true);
valueFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
value.
}
});
}
}
});
}
}