Re: Weird window close behavior
- From: Knute Johnson <nospam@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 26 Jun 2008 21:25:48 -0700
Lew wrote:
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, ...
I didn't say it was elegant, it is. I've just never seen anything like it that's all.
So why wouldn't you construct a GUI in a GUI's constructor?
--
Knute Johnson
email s/nospam/knute2008/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
.
- Follow-Ups:
- Re: Weird window close behavior
- From: Lew
- Re: Weird window close behavior
- References:
- Weird window close behavior
- From: mrstephengross
- Re: Weird window close behavior
- From: Daniel Pitts
- Re: Weird window close behavior
- From: mrstephengross
- Re: Weird window close behavior
- From: Lew
- Re: Weird window close behavior
- From: Knute Johnson
- Re: Weird window close behavior
- From: Lew
- Weird window close behavior
- Prev by Date: Re: Weird window close behavior
- Next by Date: Re: Weird window close behavior
- Previous by thread: Re: Weird window close behavior
- Next by thread: Re: Weird window close behavior
- Index(es):
Relevant Pages
|