Java 监听器 - 不监听

标签 java swing action actionlistener

我正在尝试编译此代码(如下),但我不断收到一条错误消息,指出

Multiple markers at this line

  • The type qq must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
  • The serializable class qq does not declare a static final serialVersionUID field of type long

我对 Java 还是很陌生,我真的不知道发生了什么,你们能不能知道我该如何纠正这种不幸的情况?

public class qq extends JFrame implements ActionListener, ItemListener {

    // many fields here

    public qq() {
        // components initializing
        // other code for window closing etc.
    }

    // actionPerformed is ActionListener interface method
    // which responds to action event of selecting
    // combo box or radio button
    public void ationPerformed(ActionEvent e){
        if (e.getSource() instanceof JComboBox){
            System.out.println("Customer shops: " + freqButton.getSelectedItem());
        }
        else if (e.getSource() instanceof JRadioButton){
            if (age1.isSelected() ){
                System.out.println("Customer is under 20");
            }
            else if (age2.isSelected() ){
                System.out.println("Customer is 20 - 39");
            }
            else if (age3.isSelected() ){
                System.out.println("Customer is 39 - 59");
            }
            else if (age4.isSelected() ){
                System.out.println("Customer is over 60");
            }
        }
    }

    // itemStateChanged is ItemListener interface method
    // which responds to item event of clicking checkbox
    public void itemStateChanged (ItemEvent e){
        if (e.getSource() instanceof JCheckBox){
            JCheckBox buttonLabel = (JCheckBox)
                    e.getItemSelectable();
            if (buttonLabel == tradeButton){
                if (e.getStateChange() == e.SELECTED) {
                    System.out.println("Customer is trade");
                }
                else
                {
                    System.out.println("Customer is not trade");
                }
            }
        }
    }

    public static void main(String args[]) {
        qq cd = new qq();
        // other code setting up the window
    }

}

最佳答案

更正您在 public void ationPerformed(ActionEvent e) 中的拼写错误并在“action”中添加缺失的“c”,这将处理错误消息。

您可以忽略有关 serialVersionUID 的警告,稍后当您了解有关序列化的更多信息时再回来看。

关于Java 监听器 - 不监听,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18714927/

相关文章:

javascript - Canvas 仅每隔一次点击更新一次

javascript - Ember 对 ='change' 事件的操作

java - JPanel - 定位元素

java - 重新绘制 JPanel

java - 滚动 JScrollPane 时出现问题 - 线程

Java Swing,如何在“下一步”按钮后更改布局

javascript - 在另一个 Action 之后 react Redux 调度 Action

java - 在 iPad/iPhone 上运行 JAR

java - 从ice中获取列值:dataTable in the validator of another column

java - "java.exe"退出代码 2 Xamarin.Android 项目