需要ActionListener的帮助!

时间:2011-04-26 04:21:39

标签: java

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

public class FinalExamClass extends JFrame {
    private String strName;
    private int intQuantity;
    private boolean blnInsurance;
    private double dblTotal;
    private JPanel panel;
    private JLabel nameLabel;
    private JLabel quantityLabel;
    private JTextField nameText;
    private JTextField quantityText;
    private JButton searchButton;
    private JButton submitButton;
    private JButton reportButton;
    private JButton clearButton;
    private JRadioButton cleaningRadButton;
    private JRadioButton fillingRadButton;
    private JRadioButton rootRadButton;
    private ButtonGroup radioButtonGroup;
    private final int WINDOW_WIDTH = 350;
    private final int WINDOW_HEIGHT = 250;

    // Constructor
    public FinalExamClass() {
        setTitle("Dentist Application");

        setSize(WINDOW_WIDTH, WINDOW_HEIGHT);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        buildPanel();

        add(panel);

        setVisible(true);

    }

    public void buildPanel() {
        nameLabel = new JLabel("Name: ");

        nameText = new JTextField(10);

        quantityLabel = new JLabel("Quantity; ");

        quantityText = new JTextField(10);

        searchButton = new JButton("Search");

        submitButton = new JButton("Submit");

        reportButton = new JButton("Report");

        clearButton = new JButton("Clear");

        cleaningRadButton = new JRadioButton("Cleaning");

        fillingRadButton = new JRadioButton("Filling");

        rootRadButton = new JRadioButton("Root");

        radioButtonGroup = new ButtonGroup();
        radioButtonGroup.add(cleaningRadButton);
        radioButtonGroup.add(fillingRadButton);
        radioButtonGroup.add(rootRadButton);

        cleaningRadButton.addActionListener(new RadioButtonListener());
        fillingRadButton.addActionListener(new RadioButtonListener());
        rootRadButton.addActionListener(new RadioButtonListener());

        panel = new JPanel();

        panel.add(nameLabel);
        panel.add(nameText);
        panel.add(cleaningRadButton);
        panel.add(fillingRadButton);
        panel.add(rootRadButton);
        panel.add(quantityLabel);
        panel.add(quantityText);

    }

    @Override
    public void setName(String name) {
        strName = name;
    }

    public void setQuantity(int quantity) {
        intQuantity = quantity;
    }

    public void setInsurance(boolean insurance) {
        blnInsurance = insurance;
    }

    @Override
    public String getName() {
        return strName;
    }

    public int getQuantity() {
        return intQuantity;
    }

    public boolean getInsurance() {
        return blnInsurance;
    }

    private class RadioButtonListener implements ActionListener {
        @Override
        public void actionPerformed(Action Event e) {
            String input;
            double result = 0.0;

            input = quantityText.getText();

            if (e.getSource() == cleaningRadButton) {
                result = Double.parseDouble(input) * 60;
            } else if (e.getSource() == fillingRadButton) {
                result = Double.parseDouble(input) * 75;
            } else if (e.getSource() == rootRadButton) {
                result = Double.parseDouble(input) * 89;
            }

        }
    }
}

错误说这个

Error: The type FinalExamClass.RadioButtonListener must implement the inherited abstract     method java.awt.event.ActionListener.actionPerformed(java.awt.event.ActionEvent)

1 个答案:

答案 0 :(得分:5)

你有

public void actionPerformed(Action Event e) {

应该是

public void actionPerformed(ActionEvent e) {

参数类型是ActionEvent