public class FrameTest extends Frame implements ActionListener
{
public static void mian(String args[])
{
FrameTest test =new FrameTest();
Button btTest=new Button();
btTest.addActionListener(this);
}
}
请教addActionListener的参数应该是ActionListener,这里的this是指的谁,在别人的代码里也有这样写的btTest.addActionListener(new ActionListener);
这两行代码有什么区别吗?
{
public static void mian(String args[])
{
FrameTest test =new FrameTest();
Button btTest=new Button();
btTest.addActionListener(this);
}
}
请教addActionListener的参数应该是ActionListener,这里的this是指的谁,在别人的代码里也有这样写的btTest.addActionListener(new ActionListener);
这两行代码有什么区别吗?
第二,实现了ACTION接口,却没有实现方法,这个类毫无意义
第三,this就是指本类,即FrameTest,由于实现了action,所以可以转型,放到addaction中
第四,btTest.addActionListener(new ActionListener),少了括号,也少了实现方法,无法编译通过
第五,重申一遍,我真的很想把写这段代码的人踩死!!!!!!!
楼主的代码明显临时写写想说明一下问题的,楼上所说的少括号,少实现方法,都没错,那还有main方法的main都写错了的,明白就可以了,
不过对于一个写代码的人看着一些垃圾代码确实会难受~~