🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #1127

Re: Adding an exit confirmation dialog to a JFrame

#1127
From: Kevin Dean
Date: Thu, 11 Mar 2004 21:05
72 lines
2928 bytes
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: <4050d4ef@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!t-online.de!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <4050d3d3$1@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 13:10:40 PST
From: "Kevin Dean" <NkOdSePaAnM@datadevelopment.com>
Newsgroups: borland.public.jbuilder.java.swing
References: <4050d3d3$1@newsgroups.borland.com>
Subject: Re: Adding an exit confirmation dialog to a JFrame
Date: Thu, 11 Mar 2004 16:05:37 -0500
Lines: 74
Organization: Dolphin Data Development Ltd.
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: 24.57.150.243
Message-ID: <4050d4ef@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1079039215 24.57.150.243 (11 Mar 2004 13:06:55 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!t-online.de!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail