This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Joe Ess

modifiers  RSS feed

Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"can you please explain me this one

hear why we are useing nul"
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look in the Java API documentation, you'll see that the parentComponent field is documented as follows: -

parentComponent - determines the Frame in which the dialog is displayed; if null, or if the parentComponent has no Frame, a default Frame is used
message - the Object to display

That basically tells you what you need to know. You're asking it to use a default Frame as the parent of your message dialog.

If your application is a console application, this could be appropriate. If it's an application with a Swing or AWT user interface, it is probably wrong; you should be passing a parent component - perhaps the outermost Frame of your application.

Note that using the default Frame in this, or any other, Swing method call has an unpleasant side effect. Because this Frame is out of your control, it sticks around after the rest of your application has closed down. It can keep the Swing event processing thread going and prevent your application from shutting down cleanly. You will find yourself having to use System.exit(), which is an ugly and bad way to exit a Java application. You can avoid this by always passing a component of your own as the parent of any component you create. You can create an invisible Frame of your own as the parent of anything that has no other obvious parent. When it is time to exit the application, make sure you dispose() this Frame.

By the way UseAMeaningfulSubjectLine
[ July 11, 2007: Message edited by: Peter Chase ]
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!