[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.newcomer] Re: SWING App terminates after debug

Egan, Sasha T. wrote:
Dave Toland wrote:

Setting it visible in the constructor, that is...

uhm...yeah. When I run this with java -verbose I see all the classes load and then above in the debug box it just shuts everything down and says '<terminated>'. It never brings the interface into view.

/*
 * Created on Jul 4, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package Dummies;

import java.awt.*;
import javax.swing.*;

/**
 * @author SuperUser
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class HelloFrame extends JFrame
{
    public static void main(String[] args)
    {
        new HelloFrame();
    }
    public void HelloFrame()
    {
        this.setSize(200,100);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setTitle("Hello World!");
        this.setVisible(true);
    }
}


The problem is that your constructor is declared incorrectly: C'tors do not have a return type. The way you've coded it is legal syntax in strict terms, but it is interpreting HelloWorld() as a method, not as a c'tor. Thus, main() is actually using the compiler-generated default c'tor when you say "new HelloWorld();" because you have not declared a c'tor.


BTW, Eclipse's should have warned you that your method has a constructor name (unless you disabled that warning in the compiler preferences).

HTH,
	Eric