Article View: borland.public.jbuilder.java.swing
Article #1342Re: Swing Application Hangups (Garbage Collection?)
From: Tad Frysinger [TeamB]
Date: Wed, 14 Jan 2004 19:36
Date: Wed, 14 Jan 2004 19:36
72 lines
3785 bytes
3785 bytes
Adrian -
dispose() causes all native resources (i.e. handles, graphics resources,
etc.) to be released back to the underlying OS. I'm not sure what is
causing your hangup, but I'll bet somehow you have a reference between
those two frames, so they are each holding on to a hard reference to
something causing a deadlock.
You can also structure your main app to switch between login and module
frames in a number of ways. Here is one:
public class Examples {
boolean packFrame = false;
//Construct the application
public Examples() {
ModuleFrame module = null; // Interface, hopefully!
LoginFrame l = new LoginFrame(); // login frame
l.pack();
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = l.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
l.setLocation( (screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
boolean keepGoing = true;
while ( keepGoing ) {
l.setVisible(true);
// Login is now visible. When it is closed, the user has indicated
// somehow what action should be taken, including whether to end
// the application, or open a new module. hide() is used, not
// displose()
switch ( l.getUserAction ) {
case LoginFrame.CLOSE_APPLICATION :
keepGoing = false;
break;
case LoginFrame.EXEC_MODULE :
// Determine the module, credentials, etc. and instance the
// appropriate ModuleFrame. This could be done generically
// using Java reflection, or specifically if the modules
// are unlikely to change.
ModuleFrame frame = (ModuleFrame)<mechanism of choice>;
frame.setVisible( true );
// Determine if close means close the app or not, and
// take appropriate action
break;
case LoginFrame.PASSWORD_EXCEPTION :
// etc.
}
}
//Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new Examples();
}
}
--
Tad Frysinger [TeamB]
Technical Details
Message-ID:
<40059a84$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!crtntx1-snh1.gtei.net!news.gtei.net!newsfeed1.easynews.com!easynews.com!easynews!newspeer1.nwr.nac.net!solnet.ch!solnet.ch!irazu.switch.ch!switch.ch!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3ff6c464@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,bb0ecc1565cf5dc2 X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2004-01-14 11:40:27 PST Date: Wed, 14 Jan 2004 12:36:18 -0700 From: "Tad Frysinger [TeamB]" <tfrysinger@earthlink.net> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing Subject: Re: Swing Application Hangups (Garbage Collection?) References: <3ff6c464@newsgroups.borland.com> In-Reply-To: <3ff6c464@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 67.165.213.196 Message-ID: <40059a84$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1074109060 67.165.213.196 (14 Jan 2004 11:37:40 -0700) Lines: 73 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!crtntx1-snh1.gtei.net!news.gtei.net!newsfeed1.easynews.com!easynews.com!easynews!newspeer1.nwr.nac.net!solnet.ch!solnet.ch!irazu.switch.ch!switch.ch!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail