我正在尝试编译此代码(如下),但我不断收到一条错误消息,指出
Multiple markers at this line
- The type
ActionListener.actionPerformed(ActionEvent)
- The serializable class
static
final
serialVersionUID
field of typelong
我对 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/