• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

modifiers

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"can you please explain me this one



hear why we are useing nul"
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic