繁体   English   中英

简单的退出按钮将无法正常工作

[英]Simple exit button won't work

作为序言,我是一名学生并学习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();
    }



}

将此行移动到consturctor中:

exit.addActionListener(ebHandler);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM