Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java
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=getContentPane();
c.setBackground(Color.GRAY);
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);
txt1.addActionListener(this);//?
txt2.addActionListener(this);//?
c.add(lbl1);
c.add(txt1);
c.add(lbl2);
c.add(txt2);
setTitle("ExampleD");
setSize(800,600);
setVisible(true);
}//end container
public void main(Graphics g)
{
super.paint(g);
int x=0;
int y=0;
x=Integer.parseInt(txt1.getText());
y=Integer.parseInt(txt2.getText());
//g.setBackground(Color.BLUE);
g.fillRect(100,100,x+10,y+10);
}//end paint
public void ActionPerformed(ActionEvent e)
{
repaint();
}//public static void main(String args[])
{
ExampleD e2=new ExampleD();
}
}
Posted 14-Oct-12 11:48am
Edited 14-Oct-12 11:57am
CPallini329K
v2
Comments
Wes Aday at 14-Oct-12 18:14pm
   
ActionPerformed != actionPerformed
TorstenH. at 15-Oct-12 1:46am
   
ah, already as a comment. +5, that is correct.
Rate this: bad
good
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.
Cheers
Andi
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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.
--SA
Andreas Gieriet at 15-Oct-12 2:48am
   
Thanks for your 5!
Cheers
Andi
TorstenH. at 15-Oct-12 1:41am
   
make ExampleD abstract
 
...have you ever created a GUI? Probably not.
Andreas Gieriet at 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.
Cheers
Andi
TorstenH. at 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 at 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.
Andi
 
PS: I did not vote anyone down - so, please don't attribute that on me. Thanks.
Sergey Alexandrovich Kryukov at 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.
--SA
Sergey Alexandrovich Kryukov at 15-Oct-12 10:44am
   
TorstenH,
 
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...
--SA
TorstenH. at 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 at 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?
--SA
Andreas Gieriet at 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".
 
Cheers
Andi
 
PS: I consider the topic as closed. Thanks.
Rate this: bad
good
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) {
  repaint();
}
 
Please try to "format" the code, that gives you more overview.
In Eclipse that is right click -> "Source" -> "format"
 
Should be equal in Netbeans.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 555
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 15 Oct 2012
Copyright © CodeProject, 1999-2014
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