Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

java - is not abstract and does not override abstract method actionPerforme

MainDemo is not abstract and does not override abstract method actionPerforme (ActionEvent) in ActionListener

I don't know why this error occurs whenever I compile , although I override the method (ActionPerformed) , so what is the solution?

private void ActionPerformed(ActionEvent evt)throws ClassNotFoundException,   IOException {  
    user.importEvent(jTextField1.getText());

  }  
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your code is not complete, but if you mean the actionPerformed of the ActionListener interface (swing), you didn't override it.

Overriding a method means to define/redefine a method with the same signature of that method in the corresponding interface or super class. Also the names of the method must be the same case. (Rule of case-sensitivity in java)

So if you want to override the actionListener(ActionEvent e), your method should look like this:

public void actionPerformed(ActionEvent e){
    ...
}

Another rule in overriding is that you cannot reduce the access modifier of a method. So if a method's original access modifier is protected you can only increase the access to something like public. Here the original access modifier is public, so you can only define it with public, and private is not accepted.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...