构造函数的返回值问题 class NotHelloWorldFrame extends JFrame
{
//为什么这里没有返回值呢,添加void为返回值,不能正常会在窗口,请教一下各位高手
public NotHelloWorldFrame()
{
setTitle("NotHelloWorld");
setSize(DEAFAULT_WIDTH,DEAFAULT_HEIGHT);
//add panel to frame
NotHelloWorldPanel panel = new NotHelloWorldPanel();
add(panel);
}
public static final int DEAFAULT_WIDTH = 300;
public static final int DEAFAULT_HEIGHT = 200;
}
//a panel that displays a message
class NotHelloWorldPanel extends JPanel
{
public void paintComponent(Graphics g)
{
g.drawString("Not a hello,world program", MESSAGE_X, MESSAGE_Y);
}
public static final int MESSAGE_X = 75;
public static final int MESSAGE_Y = 100;
} ------最佳解决方案-------------------- 这正式构造方法区别普通方法的地方