What is the correct way to close java visual aplication based on swing
components.
Java and Swing are proper names, hence upper
case first letter.
Please be very specific about these matters,
instead of 'talking like your IDE'.
..I would like to do this using jMenuItem.
There is no such class in the J2SE. Did you
mean a JMenuItem?
Yes.. If you used *Java* you would probably
already have found the JavaDocs, and
answered your own question.
If you mean JFrame/JMenuItem..
- add an ActionListener to the menu item.
- In the actionPerformed(ActionEvent) method,
call JFrame.setVisible(boolean).
- Since the default behaviour of a JFrame is to
hide it when the user clicks the 'close button'
in the JFrame, you will also need to call the
setDefaultCloseOperation(int) with an appropriate
value.