Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #3724
| From | "Lew" <lew@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: Weird window close be |
| Message-ID | <0JGdnQb07OQq9fnVnZ2dnUVZ_uqdnZ2d@comcast.com> (permalink) |
| Newsgroups | comp.lang.java.gui |
| References | <48645558$0$4082$b9f67a60@news.newsdemon.com> |
| Date | 2011-04-27 15:46 +0000 |
| Organization | TDS.net |
To: comp.lang.java.gui
Lew wrote:
>> <sscce file="testit/HelloWorldFrame.java" >
>> package testit;
>>
>> import java.awt.Dimension;
>> import javax.swing.JFrame;
>> import javax.swing.JLabel;
>> import javax.swing.SwingUtilities;
>>
>> /** Investigate whether frame closes after mouse passes over the frame.
>> */
>> public class HelloWorldFrame implements Runnable
>> {
>> private JFrame frame = new JFrame();
>>
>> @Override
>> public void run()
>> {
>> frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>> frame.getContentPane().add(new JLabel("hi"));
>>
>> Dimension dim = new Dimension( 100, 100 );
>> frame.setPreferredSize( dim );
>>
>> frame.pack();
>> frame.setVisible(true);
>> }
>>
>> /** main.
>> * @param args the command line arguments
>> */
>> public static void main( String[] args )
>> {
>> SwingUtilities.invokeLater( new HelloWorldFrame() );
>> }
>> }
>> </sscce>
Knute Johnson wrote:
> I'm curious, you have no constructor here. Why would you do that? I've
> never seen anyone do this to create a basic Swing GUI before.
Not true, there is a constructor. Every object has a constructor.
The whole point of the SSCCE was to show how one can avoid putting anything
other than construction in a constructor. I even said,
> Here's my recast to avoid doing anything
> besides construction in the constructor:
in order to explain why I was doing what I did.
Why wouldn't I do it that way? Haven't you read that it's a best practice to
limit constructors to construction?
Y'know, people always complain that Java is verbose, but the minute you get
elegant with your code, ...
--
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 | Find similar | Unroll thread
Re: Weird window close be "Lew" <lew@THRWHITE.remove-dii-this> - 2011-04-27 15:46 +0000
csiph-web