I have a menu class called Menu wich defines a JFrame, this class instantiates two JPanel objects which contain text fields and buttons. There is a private inner class inside each JPanel extending class which handles the events triggered by pressing the buttons.
I want to know if there is a way for the Menu class to detect the triggered events from the buttons inside the JPanels.
Could you add a listener to a JPanel in the Menu class and do something like this? :
if(event.getSource() == panel.getButton1()){
//do button1 code
}
JPanels and in fact all Swing components have property change support, and so you could easily add a PropertyChangeListener to any Component and listen for state changes. Just be sure that in the code whose state is changing to call firePropertyChange(...) after the state changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With