当前位置: 技术问答>java相关
来帮俺看看这个关于Adapter类的小程序哪里错了?
来源: 互联网 发布时间:2015-03-09
本文导语: import java.awt.*; import java.awt.event.*; public class TestAdapter extends Frame { public static void main(String[] args) { TestAdapter ta=new TestAdapter(); } public TestAdapter() { setLayout(new FlowLayout(FlowLayout.LEFT)); ...
import java.awt.*;
import java.awt.event.*;
public class TestAdapter extends Frame
{
public static void main(String[] args)
{
TestAdapter ta=new TestAdapter();
}
public TestAdapter()
{
setLayout(new FlowLayout(FlowLayout.LEFT));
Button btn=new Button("TA");
WA wa=new WA();
btn.addWindowListener(wa);
add(btn);
pack();
setVisible(true);
}
}
class WA extends WindowAdapter
{
public void windowIconified(WindowEvent we)
{
System.out.println("This is an adapter example.");
}
}
编译出错:说找不到addWindowListener()方法
import java.awt.event.*;
public class TestAdapter extends Frame
{
public static void main(String[] args)
{
TestAdapter ta=new TestAdapter();
}
public TestAdapter()
{
setLayout(new FlowLayout(FlowLayout.LEFT));
Button btn=new Button("TA");
WA wa=new WA();
btn.addWindowListener(wa);
add(btn);
pack();
setVisible(true);
}
}
class WA extends WindowAdapter
{
public void windowIconified(WindowEvent we)
{
System.out.println("This is an adapter example.");
}
}
编译出错:说找不到addWindowListener()方法
|
Button没有这个方法,AWT中只有Window,Frame,Dialog有addWindowListener()方法
|
btn.addWindowListener(wa);
Button类当然没有这个方法了,这是frame的方法,应该是它加一个listener!
Button类当然没有这个方法了,这是frame的方法,应该是它加一个listener!