Click here to Skip to main content
15,911,789 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
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


Java
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
Updated 14-Oct-12 10:57am
v2
Comments
[no name] 14-Oct-12 18:14pm    
ActionPerformed != actionPerformed
TorstenH. 15-Oct-12 1:46am    
ah, already as a comment. +5, that is correct.

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
 
Share this answer
 
Comments
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.
--SA
Andreas Gieriet 15-Oct-12 2:48am    
Thanks for your 5!
Cheers
Andi
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.
Cheers
Andi
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.
Your method actionPerformed(Event) starts with a capitalized letter. That is exclusive to classes, methods always start with small letter:

Java
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900