Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2006

Tip: Looking for answers? Try searching our database.

use JFrame before it is constructed

Thread view: 
Martijn Mulder - 12 Feb 2006 01:52 GMT
Is it safe to use JFrame before the constructor is invoked as in this code
sample:

class MyClass
{
javax.swing.JFrame jframe=new javax.swing.JFrame("MyFrame");
javax.swing.JDialog jdialog=new javax.swing.JDialog(jframe,"MyDialog");
MyClass(){}
}

Thank you
IchBin - 12 Feb 2006 02:49 GMT
> Is it safe to use JFrame before the constructor is invoked as in this code
> sample:
[quoted text clipped - 7 lines]
>
> Thank you

Sure..

Signature

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)

Chris Smith - 12 Feb 2006 03:55 GMT
> Is it safe to use JFrame before the constructor is invoked as in this code
> sample:
[quoted text clipped - 5 lines]
> MyClass(){}
> }

Your code is safe.  Note that you are NOT using a JFrame before it is
constructed, and that's why it's safe.  By the time the initialization
expression got jdialog has finished, the variable jframe is already
completely initialized.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Martijn Mulder - 12 Feb 2006 19:13 GMT
>> Is it safe to use JFrame before the constructor is invoked as in this
>> code
[quoted text clipped - 6 lines]
>> MyClass(){}
>> }

> Your code is safe.  Note that you are NOT using a JFrame before it is
> constructed, and that's why it's safe.  By the time the initialization
> expression got jdialog has finished, the variable jframe is already
> completely initialized.

I see. And is this safe?

class MyClass extends javax.swing.JFrame
{
javax.swing.JDialog jdialog=new javax.swing.JDialog(this,"MyDialog");
MyClass(){super("MyFrame");}
}
Thomas A. Russ - 13 Feb 2006 18:48 GMT
> I see. And is this safe?

Yes, at least once the accidental change of case gets corrected.
See the Java Language Reference, section 8.3.2.2

"this" can be used in the initializers of class instance variables.

> Class Myclass Extends Javax.Swing.Jframe
> {
> Javax.Swing.Jdialog Jdialog=New Javax.Swing.Jdialog(This,"Mydialog");
> Myclass(){Super("Myframe");}
> }

Signature

Thomas A. Russ,  USC/Information Sciences Institute



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.