🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Adding an exit confirmation dialog to a JFrame

#1129
From: Kevin Dean
Date: Thu, 11 Mar 2004 22:01
110 lines
4817 bytes
Passing a value into this parameter is the recommended approach.  What
you're doing by passing the frame in is telling the JOptionPane class to
make the frame the parent of the option dialog that it displays.  When you
do that, you can't change the focus of the application by clicking on your
frame.  When the value you pass in is null, clicking on the frame brings the
frame to the front (in front of the option dialog) but nothing else will
respond.  This can be quite confusing for your users who expect that a
dialog will always be on top.

-- 
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:4050dce5@newsgroups.borland.com...
> 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: <4050e2ac$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.ash.giganews.com!border2.nntp.ash.giganews.com!nntp.giganews.com!elnk-atl-nf1!newsfeed.earthlink.net!bigfeed2.bellsouth.net!bigfeed.bellsouth.net!news.bellsouth.net!peer01.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <4050d3d3$1@newsgroups.borland.com> <4050d4ef@newsgroups.borland.com> <4050dce5@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:50 PST
From: "Kevin Dean" <NkOdSePaAnM@datadevelopment.com>
Newsgroups: borland.public.jbuilder.java.swing
References: <4050d3d3$1@newsgroups.borland.com> <4050d4ef@newsgroups.borland.com> <4050dce5@newsgroups.borland.com>
Subject: Re: Adding an exit confirmation dialog to a JFrame
Date: Thu, 11 Mar 2004 17:01:45 -0500
Lines: 112
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: <4050e2ac$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1079042732 24.57.150.243 (11 Mar 2004 14:05:32 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.ash.giganews.com!border2.nntp.ash.giganews.com!nntp.giganews.com!elnk-atl-nf1!newsfeed.earthlink.net!bigfeed2.bellsouth.net!bigfeed.bellsouth.net!news.bellsouth.net!peer01.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail