Article View: borland.public.jbuilder.java.swing
Article #1130Re: Adding an exit confirmation dialog to a JFrame
From: Ron
Date: Thu, 11 Mar 2004 21:40
Date: Thu, 11 Mar 2004 21:40
86 lines
3504 bytes
3504 bytes
Thanks! I tried it and it worked, but then the question: I used null and
that worked also. Both Frame1.this and null seem to have the same
functionality, in this very tiny example. What is the difference (a pointer
to an article would help, or just "it is too complicated to go into here,"
is also ok).
RON
"Kevin Dean" <NkOdSePaAnM@datadevelopment.com> wrote in message
news:4050d4ef@newsgroups.borland.com...
> That you want is:
>
> int confirm = JOptionPane.showOptionDialog(Frame1.this, ...
>
> Using "Frame1.this" tells the compiler that you want the "this" object
> referring to the outer Frame1 class, not the "this" object referring to
the
> anonymous adapter.
>
> --
> Check out our latest white papers at
> http://www.datadevelopment.com/papers/index.html
>
> BladeNET Scores With Borland Enterprise Tools
> Team Development with JBuilder and Borland Enterprise Server
>
> Dolphin Data Development Ltd.
> http://www.datadevelopment.com/
>
> "Ron" <rgans@nospamRonaldgansphotographyDOTcom> wrote in message
> news:4050d3d3$1@newsgroups.borland.com...
> > I have a JFrame (Frame1) and in the constructor, I want to provide for
an
> > exit confirmation dialog. I add the code as follows:
> >
> > public class Frame1 extends JFrame implements WindowConstants {
> > public Frame1() {
> > super ("Focus Frame");
> >
> > //Code left out
> >
> > setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE ) ;
> > WindowAdapter a = new WindowAdapter() {
> > public void windowClosing(WindowEvent e) {
> > int confirm = JOptionPane.showOptionDialog(Frame1, "Really
> > exit?",<---ERROR HERE
> > //--->>>Error is: "Frame1.java": Error #: 300 : variable Frame1 not
found
> in
> > anonymous class of constructor Frame1()
> > //-->>>I UNDERSTAND why this is occurring, but how can I remedy it?
> > "Exit Confirmation",
> > JOptionPane.YES_NO_OPTION,
> > JOptionPane.QUESTION_MESSAGE,
> > null, null, null);
> > if (confirm == 0) {
> > //Frame1.dispose();
> > System.exit(0);
> > } //if
> > }
> > };//new
> >
> > //Frame1.windowDeactivate();
> > addWindowListener(a);
> >
> >
> > Thanks
> > RON
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > _________________________________________________________
> > Black and White Photography: http://www.ronaldgansphotography.com
> >
> >
>
>
Technical Details
Message-ID:
<4050dce5@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4050d3d3$1@newsgroups.borland.com> <4050d4ef@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,e0ae65b09d87ff96 X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2004-03-11 14:08:51 PST Reply-To: "Ron" <rgans@nospamRonaldgansphotographyDOTcom> From: "Ron" <rgans@nospamRonaldgansphotographyDOTcom> Newsgroups: borland.public.jbuilder.java.swing References: <4050d3d3$1@newsgroups.borland.com> <4050d4ef@newsgroups.borland.com> Subject: Re: Adding an exit confirmation dialog to a JFrame Date: Thu, 11 Mar 2004 16:40:54 -0500 Lines: 88 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 161.233.20.179 Message-ID: <4050dce5@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1079041253 161.233.20.179 (11 Mar 2004 13:40:53 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail