Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #3733
| From | "Lew" <lew@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: Weird window close be |
| Message-ID | <JeidnUNXGPIV7PjVnZ2dnUVZ_hWdnZ2d@comcast.com> (permalink) |
| Newsgroups | comp.lang.java.gui |
| References | <48650787$0$4089$b9f67a60@news.newsdemon.com> |
| Date | 2011-04-27 15:46 +0000 |
| Organization | TDS.net |
To: comp.lang.java.gui 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? For that I recommend further reading. I was doing it as an exercise to follow the advice I've read all over the place, is all. > And to take that a step further, if you are building a GUI in a frame, why would it > not be even better to build it totally in the main() method and avoid > distributing the code out to the run()? What's to avoid? The run() seems to me to be the natural place to do that, given that SwingUtilities.invokeLater() wants a Runnable, and we want to do the build of the GUI on the EDT. >> It was to show how one can translate that lip-service principle into >> practice that I presented the example. > > 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. So what the heck, if this is such a good idea, let's see how hard it is to implement. After all, if it's difficult, maybe one should consider not following this advice. Turns out, it's not only easy but makes for quite clean and elegant code. Thus the cost is nil, and the benefits, well, you just have to believe the pundits. I don't have enough authority. Sorry I don't have the links, but you can google them as easily as I. If you go even further, as in Joshua Bloch's /Effective Java/, Item 1, you won't use constructors at all but static factory methods. -- Lew --- * 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 | Next — Next in thread | Find similar | Unroll 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