在为组件创建监听器时,监听器不是应该继承相应接口的所有的方法吗?为什么下面的这个不用呀?
新手不懂的啦
import java.awt.*;
import java.awt.event.*;
public class Ak extends Frame implements ActionListener{
        Label label1,label2;
        TextField text1,text2,text3;
    Button button1;
    public static void main(String args[]){
            Ak fr=new Ak();
            fr.setTitle("aaa");
            fr.setSize(300,300);
            fr.setBackground(Color.red);
            fr.setLayout(new FlowLayout());
            fr.setVisible(true);
            fr.go();
    }
    public void go(){
            label1=new Label("haha");
            label1.setBackground(Color.green);
            text1=new TextField(10);
            text1.setSize(2,4);
            label2=new Label("haha");
            text2=new TextField(10);
        button1=new Button("haha");
            text3=new TextField(10);
            add(label1);
            add(text1);
            add(label2);
            add(text2);
            add(button1);
            add(text3);
            button1.addActionListener(this);
    }
    public void actionPerformed(ActionEvent e){
            float c;
            int a,b;
            a=Integer.parseInt(text1.getText());
            b=Integer.parseInt(text2.getText());
            c=a*b;
            text3.setText(String.valueOf(c));
    }

解决方案 »

  1.   

    public class Ak extends Frame implements ActionListener
    你不是已经实现了ActionListener吗
      

  2.   

    public void actionPerformed(ActionEvent e); 这个方法已经实现了=========/*
     * @(#)ActionListener.java 1.18 06/04/13
     *
     * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
     * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
     */package java.awt.event;import java.util.EventListener;/**
     * The listener interface for receiving action events. 
     * The class that is interested in processing an action event
     * implements this interface, and the object created with that
     * class is registered with a component, using the component's
     * <code>addActionListener</code> method. When the action event
     * occurs, that object's <code>actionPerformed</code> method is
     * invoked.
     *
     * @see ActionEvent
     * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/eventmodel.html">Tutorial: Java 1.1 Event Model</a>
     *
     * @author Carl Quinn
     * @version 1.18 04/13/06
     * @since 1.1
     */
    public interface ActionListener extends EventListener {    /**
         * Invoked when an action occurs.
         */
        public void actionPerformed(ActionEvent e);
    }