请教以下两种方式哪个好? 或者说在使用上好处更多? 为什么? 多谢啦!第一种:
import java.awt.*;public class Test implements ActionListener
{
public static void main(String[] args)
{
Test t = new Test();
}
public Test()
{
Frame f = new Frame("test");
Button b = new Button("BUTTON");
b.addActionListener(this);
......
}
public void actionPerformed(ActionEvent arg)
{
......
}
}========================================================================
第二种:
import java.awt.*;public class Test
{
public static void main(String[] args)
{
new MyFrame();
}
}class MyFrame extends Frame
{
Button b = new Button("BUTTON");
b.addActionListener(new Moniter());
......
}class Moniter implements ActionListener
{
public void actionPerformed(ActionEvent arg)
{
......
}
}
import java.awt.*;public class Test implements ActionListener
{
public static void main(String[] args)
{
Test t = new Test();
}
public Test()
{
Frame f = new Frame("test");
Button b = new Button("BUTTON");
b.addActionListener(this);
......
}
public void actionPerformed(ActionEvent arg)
{
......
}
}========================================================================
第二种:
import java.awt.*;public class Test
{
public static void main(String[] args)
{
new MyFrame();
}
}class MyFrame extends Frame
{
Button b = new Button("BUTTON");
b.addActionListener(new Moniter());
......
}class Moniter implements ActionListener
{
public void actionPerformed(ActionEvent arg)
{
......
}
}
第二种比第一种好,
还有一种是最好的。b.addActionListener(new ActionListener
{
public void actionPerformed(ActionEvent arg)
{
......
}
};