gpt4 book ai didi

java - 需要 ActionListener 的帮助!

转载 作者:行者123 更新时间:2023-12-01 17:36:24 24 4
gpt4 key购买 nike

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)

最佳答案

你有

public void actionPerformed(Action Event e) {

应该是

public void actionPerformed(ActionEvent e) {

参数类型为ActionEvent

关于java - 需要 ActionListener 的帮助!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5785896/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com