I have this JFrame called receipt, and what I want is when the user clicked the Exit button (top right of the JFrame) the JButton from another class will be executed.
I have added a WindowLIstener for the closing of the JFrame receipt:
@Override
public void windowClosing(WindowEvent e) {
if (JOptionPane.showConfirmDialog(null, "Do you want to have another transaction?", "New Transaction", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
reciept.this.dispose();
---------> // JButton code to be executed from another class
} else {
JOptionPane.showMessageDialog(null, "Thank you for shopping with us!");
System.exit(0);
}
}
The JButton new transaction from another class:
if (e.getSource() == transaction) {
total = 0;
cartAmount.setText("Total: ");
list.clear();
list2.clear();
list3.clear();
model.setRowCount(0);
model2.setRowCount(0);
image.setIcon(null);
iteminfo.setText("");
itemprice.setText("Price: P ");
itemstock.setText("Stocks: ");
}
Basically, the JButton new transaction just resets the Class Store, thank you so much for any help!
This sounds like an XY Problem where your best solution is to try another approach entirely:
If this doesn't appear to answer your question, then consider fleshing out your problem and your code for us, including creating and posting a valid minimimal reproducible example program in your question.