I have function dodaj(); in JFrame, and in this JFrame i have JPanel.
To use Buttons from JPanel i am using ActionListener. But when someone click on button I wanna call function dodaj(); from JFrame.
If I have ActionLIstener in JFrame i can use this.dodaj();, but i have action listener on JPanel, with is composition od JFrame.
How could i call dodaj(); (JFrame function) from ActionListener with is on JPanel?
Thanks for reading it and sorry for my bad english.
You don’t mention it, but are your JFrame and JPanels both classes, and so your problem is that you want to call a method from one class in another class? If so, the key is to get a reference to the JFrame class and pass it into the JPanel class via a constructor or method parameter.
For example:
As an aside, I don’t recommend extending JFrame or JPanel without good reason such as the need to override methods.