开发者

Need Help with ActionListener!

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 s开发者_如何学运维etName(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;
            }

        }
    }
}

THE ERROR SAYS THIS

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


you have

public void actionPerformed(Action Event e) {

it should be

public void actionPerformed(ActionEvent e) {

the parameter type is ActionEvent

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜