这段代码的问题是,每当我运行它时,它都会显示
编译错误——
“找不到符号:构造函数 mywindowadapter(frame1)
位置:类 mywindowadapter mywindowadapter mwa=new 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[])
{
frame1 f=new frame1("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=frame1 width=500 height=500>
</applet>*/
class frame1 extends Frame
{
frame1(String title)
{
super(title);
mywindowadapter mwa=new mywindowadapter(this);
addWindowListener(mwa);
}
public static void main(String ar[])
{
frame1 f=new frame1("my frame");
f.setVisible(true);
f.setSize(200,100);
}
public void paint(Graphics g)
{
g.drawString("hello frame",60,70);
}
}
class mywindowadapter extends WindowAdapter
{
frame1 f;
mywindowadapter(frame1 f)
{
this.f=f;
}
public void windowClosing(WindowEvent we)
{
f.setVisible(false);
System.exit(0);
}
}