A JButton
could be used.
A JButton
generates
actionEvents
and needs an ActionListener
that implements actionPerformed()
.
The actionPerformed()
method can call System.exit(0)
to exit the program.
Let us write a program that:
ActionListener
.actionPerformed()
method.
actionPerformed()
method calls System.exit(0)
.Often a real application has several ways to quit: the close window button, a menu selection, and perhaps a button like this program.