How would I go about closing a JFrame
based on an ActionEvent
from a button click within a JPanel
?
I have a total of three classes:
Application
: contains the main method and runs the program by creating aFrameStartUp
object.FrameStartUp
: extends theJFrame
class and displays the contents withinStartUpPanel
.StartUpPanel
: extends theJPanel
class and has all the components andActionEvents
.
Within the StartUpPanel
class, I have a button with an ActionEventListener
waiting for the button to be clicked.
When the button is clicked I want the application to shut down completely. I know of a method called .dispose()
for the JFrame
class, but I can't use it because creating an object of FrameStartUp
would just run another GUI (run by the constructor).
As I am new to programming and swing, I do not know any other way to fix this, other than getting rid of the StartUpPanel
and just creating a JPanel
within the FrameStartUp
class.
Are there any methods provided by Swing that can access the current JFrame
that the panel is on, so the program can close when the ActionEvent
is triggered?