From: Dirk Bruere at NeoPax on
Got a simple app that's a frame and a jpanel with buttons on it.
Can't work out how to close it using one of the buttons rather than the
graphical interface provided.

--
Dirk

http://www.transcendence.me.uk/ - Transcendence UK
http://www.theconsensus.org/ - A UK political party
http://www.blogtalkradio.com/onetribe - Occult Talk Show
From: Arne Vajhøj on
On 29-01-2010 18:45, Dirk Bruere at NeoPax wrote:
> Got a simple app that's a frame and a jpanel with buttons on it.
> Can't work out how to close it using one of the buttons rather than the
> graphical interface provided.

Calling the dispose method of the JFrame object should do it.

Arne
From: Roedy Green on
On Fri, 29 Jan 2010 23:45:49 +0000, Dirk Bruere at NeoPax
<dirk.bruere(a)gmail.com> wrote, quoted or indirectly quoted someone who
said :

>Got a simple app that's a frame and a jpanel with buttons on it.
>Can't work out how to close it using one of the buttons rather than the
>graphical interface provided.

Buttons are part of the GUI. Are you asking?

1. how do I close the frame gracefully and exit if my program decides
it would be a good idea?

2. what kind of code to I put in the event listener for the button to
close the frame and shut down.

See http://mindprod.com/jgloss/frame.html
http://mindprod.com/jgloss/jframe.html

The key is the Frame/JFrame.dispose method.

See also System.exit( int );
--
Roedy Green Canadian Mind Products
http://mindprod.com
Computers are useless. They can only give you answers.
~ Pablo Picasso (born: 1881-10-25 died: 1973-04-08 at age: 91)
From: Dirk Bruere at NeoPax on
Roedy Green wrote:
> On Fri, 29 Jan 2010 23:45:49 +0000, Dirk Bruere at NeoPax
> <dirk.bruere(a)gmail.com> wrote, quoted or indirectly quoted someone who
> said :
>
>> Got a simple app that's a frame and a jpanel with buttons on it.
>> Can't work out how to close it using one of the buttons rather than the
>> graphical interface provided.
>
> Buttons are part of the GUI. Are you asking?
>
> 1. how do I close the frame gracefully and exit if my program decides
> it would be a good idea?
>
> 2. what kind of code to I put in the event listener for the button to
> close the frame and shut down.
>
> See http://mindprod.com/jgloss/frame.html
> http://mindprod.com/jgloss/jframe.html
>
> The key is the Frame/JFrame.dispose method.
>
> See also System.exit( int );

Thanks guys - the word I did not know was "dispose"!

--
Dirk

http://www.transcendence.me.uk/ - Transcendence UK
http://www.theconsensus.org/ - A UK political party
http://www.blogtalkradio.com/onetribe - Occult Talk Show