Re: Weird window close behavior
- From: Lew <lew@xxxxxxxxxxxxx>
- Date: Fri, 27 Jun 2008 00:12:39 -0400
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
.
- Follow-Ups:
- Re: Weird window close behavior
- From: Knute Johnson
- 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
- 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
|