Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #3736

Re: Weird window close be

Path csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail
From "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this>
Subject Re: Weird window close be
Message-ID <xaudnRiazPo3NfvVnZ2dneKdnZydnZ2d@bt.com> (permalink)
X-Comment-To comp.lang.java.gui
Newsgroups comp.lang.java.gui
In-Reply-To <JeidnUNXGPIV7PjVnZ2dnUVZ_hWdnZ2d@comcast.com>
References <JeidnUNXGPIV7PjVnZ2dnUVZ_hWdnZ2d@comcast.com>
Content-Type text/plain; charset=IBM437
Content-Transfer-Encoding 8bit
X-Gateway time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92]
Lines 52
Date Wed, 27 Apr 2011 15:46:37 GMT
NNTP-Posting-Host 96.60.20.240
X-Complaints-To news@tds.net
X-Trace newsreading01.news.tds.net 1303919197 96.60.20.240 (Wed, 27 Apr 2011 10:46:37 CDT)
NNTP-Posting-Date Wed, 27 Apr 2011 10:46:37 CDT
Organization TDS.net
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.gui:3736

Show key headers only | View raw


  To: comp.lang.java.gui
Lew wrote:
> Knute Johnson wrote:
>> This is the part that I am curious about.  What makes it better 
>> practice to 'build' the GUI someplace other than the constructor?

I must admit I find it very natural to "construct" the GUI elements in a 
GUI object's constructor. For example: to instantiate JTextFields in the 
constructor of a subclass of JPanel.

>>
>> Honestly, I'm just curious and want to understand the thinking behind 
>> your method.  Are these best practices written down somewhere?
> 
> The thinking is that I should see how to follow the advice of these 
> pundits, which indeed is written down in many places, none of which I 
> can quote off the top of my hand.  The thinking is that I keep reading 
> how dangerous it is to use partially constructed objects, how there can 
> be uninitialized variables or thread dangers, how state of even final 
> variables can appear to change, and how one should be in the habit of 
> limiting constructors to construction. Apparently this is a new concept 
> for you, but I must have seen it in a dozen places.
> 

Doesn't the issue with partially constructed objects only arise if your 
constructor passes a reference to itself to other methods?

E.g. http://nat.truemesh.com/archives/000222.html

Or

    class ExamplePanel extends JPanel {
         ExamplePanel() {
             setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
             //                      ^^^^ partially constructed!
             add(new JLabel("One"));
             add(new JLabel("Two"));
             add(new JLabel("Three"));
         }
     }

Since the ancestral JComponent() constructor will have been completed 
before BoxLayout() gets to make use of it - isn't it a fully constructed 
JComponent so far as BoxLayout is concerned?

-- 
RGB

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Weird window close be "Lew" <lew@THRWHITE.remove-dii-this> - 2011-04-27 15:46 +0000
  Re: Weird window close be "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:46 +0000
    Re: Weird window close be "Lew" <lew@THRWHITE.remove-dii-this> - 2011-04-27 15:46 +0000

csiph-web