Java 简单退出按钮赢得';行不通

Java 简单退出按钮赢得';行不通,java,swing,compiler-errors,jbutton,Java,Swing,Compiler Errors,Jbutton,作为前言,我是一名学生,正在学习Java。我很享受,但简单的事情如果不起作用就会让人非常沮丧。我得到以下错误 PropertyTax2.java:85: error: cannot find symbol public class ExitHandler implements ActionListener ^ symbol: class ActionListener location: class PropertyTax

作为前言,我是一名学生,正在学习Java。我很享受,但简单的事情如果不起作用就会让人非常沮丧。我得到以下错误

PropertyTax2.java:85: error: cannot find symbol
public class ExitHandler implements ActionListener
                                    ^
symbol:   class ActionListener
location: class PropertyTax2
PropertyTax2.java:87: error: cannot find symbol
public void actionPerformed(ActionEvent e)
                                ^
symbol:   class ActionEvent
location: class PropertyTax2.ExitHandler
PropertyTax2.java:81: error: method addActionListener in class AbstractButton cannot be   applied to given types;
exit.addActionListener(ebHandler);
        ^

required: ActionListener
found: PropertyTax2.ExitHandler
reason: actual argument PropertyTax2.ExitHandler cannot be converted to ActionListener   by method invocation conversion
3 errors
守则:

import javax.swing.*;
import java.awt.*;

public class PropertyTax2 extends JFrame
{
    // set parameters to define extent of the window
    //changed width to 500 since the words were getting cut off
    private static final int WIDTH = 500, HEIGHT = 300; 

    //Declare and initialize 6 JLabels
        JLabel assessL = new JLabel("Assessment Home Value: ", SwingConstants.RIGHT);
        JLabel schoolTaxL = new JLabel("Decimal Value of School Tax Rate: ", SwingConstants.RIGHT);
        JLabel countyTaxL = new JLabel("Decimal Value of County Tax Rate: ", SwingConstants.RIGHT);
        JLabel totalSchoolTaxL = new JLabel("School Taxes: ", SwingConstants.RIGHT);
        JLabel totalCountyTaxL = new JLabel("County Taxes: ", SwingConstants.RIGHT);
        JLabel totalTaxesL = new JLabel("Total Taxes: ", SwingConstants.RIGHT);

    //Declate and initialize 5 JTextFields
        JTextField assessTF = new JTextField(10);
        JTextField schoolTaxTF = new JTextField(10);
        JTextField countyTaxTF = new JTextField(10);
        JTextField totalSchoolTaxTF = new JTextField(10);
        JTextField totalCountyTaxTF = new JTextField(10);
        JTextField totalTaxesTF = new JTextField(10);

    //Declare and Exit button

        JButton exit = new JButton("Exit");
        ExitHandler ebHandler = new ExitHandler();


    //Declare and Calculate button
        JButton calculate = new JButton("Calculate"); 





    public PropertyTax2()
    {
    //Declare and initialize a container
        Container pane = getContentPane();
    //Set the container layout
        pane.setLayout(new GridLayout(7,2));
    //Set GUI objects in the container
        pane.add(assessL);
        pane.add(assessTF);
        pane.add(schoolTaxL);
        pane.add(schoolTaxTF);
        pane.add(countyTaxL);
        pane.add(countyTaxTF);
        pane.add(totalSchoolTaxL);
        pane.add(totalSchoolTaxTF);
        pane.add(totalCountyTaxL);
        pane.add(totalCountyTaxTF);
        pane.add(totalTaxesL);   
        pane.add(totalTaxesTF);
        pane.add(exit);
        pane.add(calculate);


    // set title, size and visibility aspects of window
    setTitle("Calculation of Property Taxes");
    setSize(WIDTH, HEIGHT);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    exit.addActionListener(ebHandler);

    }

    public class ExitHandler implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            System.exit(0);
        }
    }


    public static void main(String[] args)
    {
    // main program to invoke constructor
    PropertyTax2 proptax = new PropertyTax2();
    }



}

将此行移到constructor中:

exit.addActionListener(ebHandler);

谢谢-明白了,现在我的接口类搞砸了!对不起,我没听懂。怎么搞砸了?我应该和你分享你修改过的代码吗?哈哈-我真蠢。。。导入java.awt.event.*;他失踪了。一切都准备好了!!!!!!!!!!!!!!