那匿名内部类有什么特点呢?
请说明一下好吗?
我们公司就只能上csdn别的上不上的。

解决方案 »

  1.   

    public class A extends JApplet implements ActionListener {
        ......
        public void actionPerformed(ActionEvent e){
        
        }
        ......
    }
    这样应该也可以。这就是把actionPerformed(AcionEvent e)写在外面。
      

  2.   

    还是不行啊,我不知道是不是我改的有问题,大家看看吧
    帮我纠正以下。我在eclipse中编译都没通过。
    它报错的是
    java.lang.Error: Unresolved compilation problem: 
    The type ActionListener cannot be instantiated at A.init(A.java:15)
    at A.main(A.java:30)
    而且在btn.addActionListener(new ActionListener());中的ActionListener()有红色的下划线。
    public class A extends JApplet implements ActionListener{
    JTextField text;
    JButton btn; 
    public void init() {
    text = new JTextField(10); 
    btn = new JButton("确定"); 
    getContentPane().setLayout(new FlowLayout());
    getContentPane().add(text);
    getContentPane().add(btn);
    btn.addActionListener(new ActionListener());
    }
    public void actionPerformed(ActionEvent e){
    if(e.getSource()==btn) {
    text.setText("刚点击了,:"+btn.getText()); 
    }
    }
     

    public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JApplet a = new A();
    frame.getContentPane().add(a);
    frame.setSize(200, 100);
    a.init();
    a.start();
    frame.setLocation(300,500);//居屏幕中央显示
    frame.setVisible(true);
    }
    }
      

  3.   

    你想干什么,为什么非要用APPLET呢,就用JPANEL不是挺好吗?如果没有别的特殊用途还是改用Jpanel吧,这个事件相应问题没有什么,那个对象加了事件接收器就可以响应事件了,
    至于匿名类,只是一种用法。还可以用适配器的对吧