Re: Weird window close behavior



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
.



Relevant Pages

  • Re: Choice sequences, intuition, etc
    ... |disjunctive connective - it says "either there is a construction ... have peace of mind, whether they are safe, whether they can ... them have taken paradigm shifts as being such radical ... adopted a "constructivist" frame of mind. ...
    (sci.logic)
  • Re: Which workbench to buy?
    ... frame with some hammered gray paint. ... If one has the slightest grasp of construction ... You will also need to re weld the feet to ... I moved the feet in so I wouldn't trip over ...
    (rec.crafts.metalworking)
  • Re: Paging the M4 elevated section-isti
    ... the massive Audi garage under construction (I shouldn't think they'll be ... in any hurry to finish that building anytime soon), ... frame for one on the westbound ...
    (uk.rec.motorcycles)
  • Re: Falcon Rapier - advice needed
    ... If it is a steel frame that is worth upgrading it should have material ... In the 80's, Falcon had everything from ... the materials, components, design and construction were generally fine. ...
    (uk.rec.cycling)