Reputation:
I'm trying to compile this code (below) but I keep receiving an error message stating
Multiple markers at this line
- The type
ActionListener.actionPerformed(ActionEvent)
- The serializable class
static
final
serialVersionUID
field of typelong
I'm still quite new to Java and I can't really figure out what's going on, would you all happen to have any insight onto how I might rectify this unfortunate situation?
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
}
}
Upvotes: 1
Views: 387
Reputation: 3854
You have a typo in your method name ationPerformed it should be actionPerformed
Upvotes: 2
Reputation: 7634
You need to implement the actionPerformed
method. You seem to have implemented it as ationPerformed
thus, you need to fix that spelling. Because you have not correctly implemented the interface, you cannot use the class as an ActionListener.
As to the serializable issue - this is to do with the fact that JFrame implements the Serializable interface, which requires a serialVersionUID. You can compile without one, but the IDE will complain. [For more info, see here]
As a side note, generally you don't want to extend JFrame, instead use an instance in your class.
Upvotes: 2
Reputation: 11921
Corrrect your typo in public void ationPerformed(ActionEvent e)
and add the missing "c" in "action", this will take care of the error message.
You can ignore the warning about the serialVersionUID for, come back to that later when you learn more about Serialization.
Upvotes: 2