你可以不写,但它也得自动调用父类的无参构造函数的,
public Frame(String title):
Constructs a new, initially invisible Frame object with the specified title
public Frame(String title):
Constructs a new, initially invisible Frame object with the specified title
调试欢乐多
但是这样就会调用没有参数的 Frame(), 那 MYframe(String str)里的str就没有作用了。即 MYframe fr=new MYframe("Hello OUt There!");
--------------------- 这里无论输入什么,结果都一样。
import java.awt.*;
public class MYframe extends Frame{
public static void main(String arg[]){
MYframe fr=new MYframe("Hello OUt There!");
Panel pan=new Panel();
fr.setSize(200,200);
fr.setBackground(Color.blue);
fr.setVisible(true);
pan.setSize(100,100);
pan.setBackground(Color.green);
fr.add(pan);
}
public MYframe(String str){
super(str);} public MYfrmae(){ //提供无参构造函数
super();}
}