Click here to Skip to main content
13,198,322 members (68,984 online)
Rate this:
Please Sign up or sign in to vote.
See more:
this is a simple code for JAVA GUI it gives me the error
ExampleD is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener
public class ExampleD extends JFrame implements ActionListener

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ExampleD extends JFrame implements ActionListener//?
Container c;
JLabel lbl1,lbl2;
JTextField txt1,txt2;
public ExampleD()
c.setLayout(new FlowLayout(FlowLayout.LEFT));
lbl1=new JLabel("enter the width");
lbl2=new JLabel("enter the hight");
txt1=new JTextField(10);
txt2=new JTextField(10);
}//end container
public void main(Graphics g)
int x=0;
int y=0;
}//end paint
public void ActionPerformed(ActionEvent e)
}//public static void main(String args[])
ExampleD e2=new ExampleD();
Posted 14-Oct-12 10:48am
Updated 14-Oct-12 10:57am
Wes Aday 14-Oct-12 18:14pm
ActionPerformed != actionPerformed
TorstenH. 15-Oct-12 1:46am
ah, already as a comment. +5, that is correct.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Fix the error:
ExampleD is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener.
Either make ExampleD abstract or implement in ExampleD the above mentioned method.
Sergey Alexandrovich Kryukov 14-Oct-12 21:43pm
That's correct, my 5, but I'm not sure OP can get it, as the question demonstrate that the idea of abstract and interface implementation is not understood.
Andreas Gieriet 15-Oct-12 2:48am
Thanks for your 5!
TorstenH. 15-Oct-12 1:41am
make ExampleD abstract

...have you ever created a GUI? Probably not.
Andreas Gieriet 15-Oct-12 2:48am
Shall I say "thank you for your 1"? Probably not ;-)
It's not about GUI, it's about reading error messages and act accordingly.
TorstenH. 15-Oct-12 3:00am
You didn't even read the question. You just used the chance to place a rant.

But that seems to be normal - vote all beginners down and rant. Don't know what's currently wrong in the CP Java section.
Andreas Gieriet 15-Oct-12 4:48am
Cool down. I don't know where your anger comes from. It seems you are upset by my short reply to the OP's question. My hint was: If one reads the error message carefully enough, one gets the solution himself. I'm exposed to tons of such questions outside CP and I experience careless reading of error messages day in and out. So, I think the problem is rooted in "reading and understanding" error messages irrelevant of the application (GUI or anything else) and the language (Java or anything else).
My appologies if I upset you.

PS: I did not vote anyone down - so, please don't attribute that on me. Thanks.
Sergey Alexandrovich Kryukov 15-Oct-12 10:48am
I agree with you; see also my reply to TorstenH. I don't think your answer needs excuses.
However, the accusation in "not reading" the answer could cause the well-known reply "I don't need to eat a whole egg to tell it's bad". And the answer is not a rant; it provides a positive advice.
Sergey Alexandrovich Kryukov 15-Oct-12 10:44am

I think that your anger and sarcasm is not motivated. The note about GUI is strange. How is it related? At least explain it.
The question addresses illogical thinking of OP and provides a valid hint, which is way more valuable than answering with some cookbook recipes...
TorstenH. 15-Oct-12 19:46pm
A abstract GUI - think about it for a moment.
A abstract Object is never to be called directly. So one can't create a abstract GUI.
An error message asking "to implement a function or to make the object abstract" is caused due to inheriting methods from some interface. Reading the first lines of code one does see that he extends JFrame and implements the interface ActionListener.

But to see that one does need to read the question and probably be used to Java code.
Sergey Alexandrovich Kryukov 15-Oct-12 21:22pm
Of course. Perhaps you did not understand the solution. The idea was: make it abstract and of course don't use. Use some derived class. I'm too far from the idea that Andi don't understand that an abstract class cannot be instantiated. OK?
Andreas Gieriet 16-Oct-12 2:57am
Hello TorstenH,

We seem to have set a very different focus on answering the question. Both of us assume a beginner, but come up with different styles of answers. You did choose to give the solution directly, so no reflection on the issue is needed by the OP. My approach was to trigger thinking of the OP: there is an error message and I did rephrase in some concise way - now the OP has the "choice" to do one or the other to make his own experience. He now must make a decision: A) make the class abstract? --> no, since he needs to instanciate the class directly --> B) so, the other option is the only one to go --> create the method --> ah, there is already one that resembles this one, just the capital letter is wrong --> ...

Learn effect can be achieved in various ways, I choose my style.

Now you can continue blaming people for not reading questions or not understanding things or accusing for ranting...
Go ahead with your "style".


PS: I consider the topic as closed. Thanks.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Your method actionPerformed(Event) starts with a capitalized letter. That is exclusive to classes, methods always start with small letter:

public void actionPerformed(ActionEvent e) {

Please try to "format" the code, that gives you more overview.
In Eclipse that is right click -> "Source" -> "format"

Should be equal in Netbeans.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171020.1 | Last Updated 15 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100