这段代码的问题是,每当我运行它时,它都会显示编译错误:
找不到符号:构造函数 mywindowadapter(frame1)
位置:class mywindowadapter
mywindowadapter mwa=新的 mywindowadapter()"
import java.awt.*;
import java.awt.event.*;
/*<applet code=frame2 width=500 height=500>
</applet>*/
class frame2 extends Frame
{
frame2(String title)
{
super(title);
mywindowadapter mwa=new mywindowadapter();
addWindowListener(mwa);
}
public static void main(String ar[])
{
frame2 f=new frame2("my frame");
f.setVisible(true);
f.setSize(200,100);
}
public void paint(Graphics g)
{
g.drawString("hello frame",60,70);
}
}
class mywindowadapter extends WindowAdapter
{
mywindowadapter()
{
frame2 f=new frame2();
}
public void windowClosing(WindowEvent we)
{
f.setVisible(false);
System.exit(0);
}
}
下面的代码是上面代码的修正版。我无法理解前面代码中生成的错误。请帮忙!!
import java.awt.*;
import java.awt.event.*;
/*<applet code=frame2 width=500 height=500>
</applet>*/
class frame2 extends Frame
{
frame2(String title)
{
super(title);
mywindowadapter mwa=new mywindowadapter(this);
addWindowListener(mwa);
}
public static void main(String ar[])
{
frame2 f=new frame2("my frame");
f.setVisible(true);
f.setSize(200,100);
}
public void paint(Graphics g)
{
g.drawString("hello frame",60,70);
}
}
class mywindowadapter extends WindowAdapter
{
frame2 f;
mywindowadapter(frame2 f)
{
this.f=f;
}
public void windowClosing(WindowEvent we)
{
f.setVisible(false);
System.exit(0);
}
}