Article View: borland.public.jbuilder.java.language
Article #19785Re: Closing frame windows...
From: Robert D. Cleary
Date: Mon, 15 Dec 1997 00:00
Date: Mon, 15 Dec 1997 00:00
83 lines
3723 bytes
3723 bytes
This is a multi-part message in MIME format.
--------------E606C6D908A2B086B4F2D732
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Michael J. Rozlog wrote:
> The reason for this code, have you notice if you hit the "x" method at the
> top right hand corner it closes the whole application, even if you have
> exitOnClose set to false on the second frame. This is most likely a bug!
> To get around this, you can use a wizard to help you with the writing of
> the code. In the second frame, while in the source, go to the wizard menu
> item and choose the override wizard. From there, click the "+" symbol on
> the DecoratedFrame and select the processWindowEvent and select "ok". This
> will put the appropriate code into the program. Now lets look at the logic
> in the Decorated frame by going to the structure pane and double-clicking
> on the DecoratedFrame object, this of-course takes us to the source for the
> DecoratedFrame now select the blue arrow icon which represents a method for
> the processWindowEvent. The cursor should be located on the event, it
> should look like this:
>
> protected void processWindowEvent(WindowEvent e) {
> super.processWindowEvent(e);
> if (e.getID() == WindowEvent.WINDOW_CLOSING && getParent() == null &&
> exitOnClose)
> System.exit(0);
> }
>
> If you test it out you will come to the conclusion that it should be
> (not)exitOnClose or !exitOnClose. The code is telling us to close the
> frame regardless of the exitOnClose value. To un-display a frame you call
> its dispose() method. By the by, when you call dispose() it does not do
> garbage collection on the frame unless it is out of scope. We modify the
> if statement to check if exitOnClose is not true then just displose(), else
> we call the super method and continue regular processing.
>
I just use this code with the frame that you want to close:
protected void processWindowEvent(WindowEvent e)
{
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
this.dispose();
}
}
The Frames X button and Icon drop down Close both close the form without exiting
the whole applicaton.
I call it on a button click with:
void button1_actionPerformed(ActionEvent e) {
Frame2 frame2 = new Frame2();
frame2.setLocation(400,0);
frame2.validate();
frame2.show();
}
--------------E606C6D908A2B086B4F2D732
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Robert D. Cleary
Content-Disposition: attachment; filename="vcard.vcf"
begin: vcard
fn: Robert D. Cleary
n: Cleary;Robert D.
org: Group Multimedia Network Corp.
adr;dom: 70 Jefferson Avenue;;;Toronto, Ontario, Canada;;M6K 1Y4;
email;internet: robertc@gmn.com
title: Computer Programmer / Analyst
tel;work: 416.539.0694 ext 119
tel;fax: 416.539.8626
x-mozilla-cpt: ;0
x-mozilla-html: FALSE
version: 2.1
end: vcard
--------------E606C6D908A2B086B4F2D732--
Technical Details
Message-ID:
<349575CC.62DA892A@gmn.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<346493C4.8E07FFC6@freemail.gr> <34654F8E.B4C5EDB1@msn.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,94bc9b1ceb724919 X-Google-Attributes: gidf74b3,public From: "Robert D. Cleary" <robertc@gmn.com> Subject: Re: Closing frame windows... Date: 1997/12/15 Message-ID: <349575CC.62DA892A@gmn.com> X-Deja-AN: 298416418 References: <346493C4.8E07FFC6@freemail.gr> <34654F8E.B4C5EDB1@msn.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------E606C6D908A2B086B4F2D732" Organization: Group Multimedia Network Corp. Newsgroups: borland.public.jbuilder.java.language