问题描述
importjava.awt.*;publicclassT1extendsFrame{publicstaticvoidmain(String[]args){T1fr=newT1("HelloOutThere!");fr.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});fr.setSize(200,200);fr.setBackground(Color.red);fr.setVisible(true);}
解决方案
解决方案二:
T1fr=newT1("HelloOutThere!");你在你继承类T1里面没有写带参数的构造方法吧?你想调用父类的构造方法应该写成:T1fr=newFrame("HelloOutThere!");
解决方案三:
忘记了一点,前面类型应该是:Framefr=newFrame("HelloOutThere!");另外你还要引入相关包:importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;
解决方案四:
稍微帮你修改了一下,追加了一下构造方法,代码如下importjava.awt.Color;importjava.awt.Frame;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;publicclassT1extendsFrame{publicT1(Stringstring){}/***@paramargs*/publicstaticvoidmain(String[]args){T1fr=newT1("HelloOutThere!");fr.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});fr.setSize(200,200);fr.setBackground(Color.red);fr.setVisible(true);}}
解决方案五:
要加一个带参构造方法publicT1(Stringstring){super(string);}
解决方案六:
综合一下上面两位的意见,把代码改成这样。importjava.awt.Color;importjava.awt.Frame;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;publicclassT1extendsFrame{publicT1(StringfName){super(fName);}/***@paramargs*/publicstaticvoidmain(String[]args){T1fr=newT1("HelloOutThere!");fr.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});fr.setSize(200,200);fr.setBackground(Color.red);fr.setVisible(true);}}
解决方案七:
引用1楼yangjianhui123的回复:
T1fr=newT1("HelloOutThere!");你在你继承类T1里面没有写带参数的构造方法吧?你想调用父类的构造方法应该写成:T1fr=newFrame("HelloOutThere!");
引用4楼sunyiz的回复:
要加一个带参构造方法JavacodepublicT1(Stringstring){super(string);}
+1
解决方案八:
6楼头像好漂亮.
解决方案九:
importjava.awt.event.*;importjava.awt.*;publicclassHelloextendsFrame{publicHello(){}publicHello(Strings){this.setTitle(s);}publicstaticvoidmain(String[]args){Hellofr=newHello("HelloOutThere!");fr.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});fr.setSize(200,200);fr.setBackground(Color.red);fr.setVisible(true);}}这个没问题
解决方案十:
是唉,我发现现在的头像不能换了的
解决方案十一:
不知道怎么回事的
解决方案十二:
该回复于2010-12-21 09:16:53被版主删除
解决方案十三:
importjava.awt.*;publicclassT1extendsFrame{publicstaticvoidmain(String[]args){T1fr=newT1("HelloOutThere!");fr.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});fr.setSize(200,200);fr.setBackground(Color.red);fr.setVisible(true);}
解决方案十四:
importjava.awt.*;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;publicclassT1extendsFrame{publicT1(Stringstring){//TODO自动生成构造函数存根}publicstaticvoidmain(String[]args){T1fr=newT1("HelloOutThere!");fr.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});fr.setSize(200,200);fr.setBackground(Color.red);fr.setVisible(true);}}以上是正确的代码,需要重写String方法和导入java.awt.event.WindowAdapter和java.awt.event.WindowEvent;
解决方案十五:
该回复于2010-12-21 09:46:32被版主删除