🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #17196

Re: Disposing of a frame

#17196
From: Paul Furbacher
Date: Tue, 01 Dec 1998 00:00
51 lines
1842 bytes
Tor Iver Wilhelmsen wrote:
> 
> Leo Cohen <lcohen@cs.virginia.edu> writes:
> 
> > Therefore, given (Object v), how can I dispose() of v?
> 
> try {
>   ((Frame) v).dispose();
> }
> catch (ClassCastException cce) {
>   System.out.println("Hey! "+v+" isn't a Frame!?");
> }
> 
> Or, more complicated (using java.lang.reflect.*)
> 
> try {
>    Method m = v.getClass().getMethod("dispose", new Class[] {});
>    m.invoke(v, new Object[] { });
> }
> catch (Exception e) { // A catch-all
>   e.printStackTrace();
> }

Or:

  void disposeFrame(Object o) {
    if ( o instanceof Frame ) {
      System.out.println("disposing frame");
      ((Frame)o).dispose();
    }
  }

Try it out:

  disposeFrame(new com.sun.java.swing.JFrame());
  disposeFrame(new Frame());
  disposeFrame(new ListControl()); 
  disposeFrame(new DecoratedFrame());

Look at the output in the Execution Log window.
All but the third will result in a print out:

  disposing frame

Note that with the disposal of the DecoratedFrame, 
the application will quit since that is the default
behavior upon disposing of a DecoratedFrame [see
DecoratedFrame.isExitOnClose()].


Paul Furbacher
Technical Details
Message-ID: <36641AA4.5A9472BD@bilbo.bio.purdue.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <366312C6.92972C0C@cs.virginia.edu> <ud864rst0.fsf@sds.no>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,7c91af6c592c4d07
X-Google-Attributes: gidf74b3,public
From: Paul Furbacher <pf@bilbo.bio.purdue.edu>
Subject: Re: Disposing of a frame
Date: 1998/12/01
Message-ID: <36641AA4.5A9472BD@bilbo.bio.purdue.edu>
X-Deja-AN: 417513001
Content-Transfer-Encoding: 7bit
References: <366312C6.92972C0C@cs.virginia.edu> <ud864rst0.fsf@sds.no>
To: LeoCohen <lcohen@cs.virginia.edu>
Content-Type: text/plain; charset=us-ascii
Organization: Biological Sciences, Purdue Univ.
Mime-Version: 1.0
Reply-To: pf@bilbo.bio.purdue.edu
Newsgroups: borland.public.jbuilder.java.language