Close window by clicking Jbutton

Asked

Viewed 661 times

1

It is possible by clicking a button and the JFrame be closed as if you had clicked on the window X? If possible, how do I create it?

From what I’ve studied is using ActionListener but I can’t find the code to close the window.

1 answer

3


It is possible yes, you set a Switch to the button and inside it, invoke the method dispose() of the instance of JFrame you want to close inside this System:

botao.addActionListener(e -> seuFrame.dispose());
  • Just one more question and it is possible to call the frame I used.Ispose(); dnv if you want?

  • @Bitsofbytes if it is the only frame of the application, no, because JVM will close the application. If you have others, you need to create a new instance.

  • the application of more than 1 frame as I do?

  • @Bitsofbytes don’t understand what you’re saying.

  • let me know how I’m gonna do it

Browser other questions tagged

You are not signed in. Login or sign up in order to post.