加void与不加void的问题???
为什么下面中的public voidframe1() 中加上void就会出现C:Documents and SettingsAdministrator桌面Class1.java:12: call to super must be first statement in constructor super("我的应用程序");的错误?不加没有什么事,为什么?
import java.awt.*;
import java.awt.event.*;
class frame1 extends Frame implements ActionListener
{
public (void )frame1()
{
super("我的应用程序");
setLayout(new FlowLayout(FlowLayout.LEFT));
setBackground(Color.blue);
setSize(500,500);
setLocation(100,100);
add(new Button("确定"));
add(new Button("取消"));
Button btn=new Button("退出");
add(btn);
btn.addActionListener(this);
add(new Label("请输入数据:",Label.CENTER));
add (new TextField("文本框",10));
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
public class Class1
{
public static void main(String args[])
{
new frame1();
}
}
搜索更多相关的解决方案:
void
----------------解决方案--------------------------------------------------------
对 super 的调用必须是构造函数中的第一个语句 super("我的应用程序");
这个错误一看就知道了吧……
你加了void就不是构造函数了呀……
----------------解决方案--------------------------------------------------------
只有在构造函数中才能调用super()这个语句
因为你加了void就不是构造函数了,它就不能调用super();
你把super()去了,它就可以运行了
----------------解决方案--------------------------------------------------------
JAVA 里面的构造函数呀返回一个构造的对象,你如果在构造函数前加上void 就相当与是在构造函数的第一句声明在这个构造函数中不返回任何对象,这样做1.你即使调用构造方法,也不会返回任何对象,2。super语句在构造方法中不是第一句拉
----------------解决方案--------------------------------------------------------
谢谢大家,我明白了。
----------------解决方案--------------------------------------------------------



