CLASS is not abstract and does not override abstract method error

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 6834 Views - Last Post: 26 May 2010 - 07:59 PM Rate Topic: -----

#1 nods  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 68
  • Joined: 09-December 09

CLASS is not abstract and does not override abstract method error

Posted 26 May 2010 - 01:38 PM

HI

I am getting a CLASS is not abstract and does not override abstract method....... error when I try and compile this code. I have looked at the other post regarding this error and I still can't solve it. Can anyone help?

 */import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class PropertyUI extends JFrame implements ActionListener {
public static void main(String[] args) {


    JFrame frame = new JFrame("Group15PropertyMGTsystem");
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(800,400);
    JPanel panel1 = new JPanel();
    frame.add(panel1);
    JButton button1 = new JButton("Add  New Property");
    panel1.add(button1);
    button1.addActionListener(new Action1());
    JButton button2 = new JButton("Vew Property Details");
    panel1.add(button2);
    button2.addActionListener(new Action2());
    JButton button3 = new JButton("Ammend Property Details");
    panel1.add(button3);
    button3.addActionListener(new Action3());
    JButton button4 = new JButton("Close");
    panel1.add(button4);
    button4.addActionListener(new Action4());
    
    
   
    
}


    static class Action1 implements ActionListener{
        
        public void actionPerformed(ActionEvent e){
            
          HireEmp h=new HireEmp();
            
           
            

        }
}
    static class Action2 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
            
            ViewDetails v=new ViewDetails();
}
}
        static class Action3 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
            
            ChangeIncome i=new ChangeIncome();
        }
    }
        
        static class Action4 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
            
            System.exit(0);
        }    
        
            
        
    
        
            
}
}


Many thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: CLASS is not abstract and does not override abstract method error

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3089
  • View blog
  • Posts: 19,137
  • Joined: 14-September 07

Re: CLASS is not abstract and does not override abstract method error

Posted 26 May 2010 - 01:41 PM

When you implement an interface you have to override each function it contains.
Was This Post Helpful? 1
  • +
  • -

#3 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2553
  • View blog
  • Posts: 10,646
  • Joined: 20-September 08

Re: CLASS is not abstract and does not override abstract method error

Posted 26 May 2010 - 01:55 PM

PropertyUI does not implement ActionListener as you state, hence your error. Other classes do, but that's a different issue
Was This Post Helpful? 0
  • +
  • -

#4 nods  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 68
  • Joined: 09-December 09

Re: CLASS is not abstract and does not override abstract method error

Posted 26 May 2010 - 01:59 PM

Thx for the reply but I am still unsure how to fix it. When I remove the action listener from Propert UI non of the buttons work!!

Any guidance would be much apreciated.
Was This Post Helpful? 0
  • +
  • -

#5 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2553
  • View blog
  • Posts: 10,646
  • Joined: 20-September 08

Re: CLASS is not abstract and does not override abstract method error

Posted 26 May 2010 - 02:11 PM

Change to

public class PropertyUI extends JFrame {


Was This Post Helpful? 0
  • +
  • -

#6 nods  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 68
  • Joined: 09-December 09

Re: CLASS is not abstract and does not override abstract method error

Posted 26 May 2010 - 02:32 PM

I have tried that previously but that gives me the same error in the main class.

Let me explain in more detail

I have 2 classes. The main class called 'Group13ProjectMGTsystem' impliments the 'Property UI' class when the Jbutton is pressed. This was working fine until I added buttons that impliment other classes to the PropertyUI class.

Now the 'Group13ProjectMGTsystem' class gives the error unless I remove the 'implimentsActionlistener' but with it removed the buttons do not work. code for bot classes below.

 */import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Group13PropertyMGTsystem extends JFrame{
public static void main(String[] args) {

    JFrame frame = new JFrame("Group13PropertyMGTsystem");
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(800,400);
    JPanel panel1 = new JPanel();
    frame.add(panel1);
    JButton button1 = new JButton("Property Maintenance");
    panel1.add(button1);
    button1.addActionListener(new Action1());
    JButton button2 = new JButton("Client Maintenance");
    panel1.add(button2);
    button2.addActionListener(new Action2());
    JButton button3 = new JButton("Tennant Maintenance");
    panel1.add(button3);
    button3.addActionListener(new Action3());
    JButton button4 = new JButton("Payments");
    panel1.add(button4);
    button4.addActionListener(new Action4());
    JButton button5 = new JButton("Invoice");
    panel1.add(button5);
    button5.addActionListener(new Action5());
    
    
   
    
}
    static class Action1 implements ActionListener{
        
        public void actionPerformed(ActionEvent e){
            
          PropertyUI p=new PropertyUI();
            
           
            

        }
}
    static class Action2 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
            JFrame frame3 = new JFrame ("Add Client");
            frame3.setVisible(true);
            //frame3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame3.setSize(300,300);
            
}
}
        static class Action3 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
            JFrame frame4 = new JFrame ("Add Tennant");
            frame4.setVisible(true);
            //frame4.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame4.setSize(300,300);
            
        }
    }
        
        static class Action4 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
            JFrame frame5 = new JFrame ("Property Search");
            frame5.setVisible(true);
            //frame5.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame5.setSize(300,300);
            
        }    
        }
        static class Action5 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
            JFrame frame6 = new JFrame ("Rent Payments");
            frame6.setVisible(true);
            //frame6.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame6.setSize(300,300);
            
        }
    
        
            
}
}





/import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class PropertyUI extends JFrame {
public static void main(String[] args) {


    JFrame frame = new JFrame("Group15PropertyMGTsystem");
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(800,400);
    JPanel panel1 = new JPanel();
    frame.add(panel1);
    JButton button1 = new JButton("Add  New Property");
    panel1.add(button1);
    button1.addActionListener(new Action1());
    JButton button2 = new JButton("Vew Property Details");
    panel1.add(button2);
    button2.addActionListener(new Action2());
    JButton button3 = new JButton("Ammend Property Details");
    panel1.add(button3);
    button3.addActionListener(new Action3());
    JButton button4 = new JButton("Close");
    panel1.add(button4);
    button4.addActionListener(new Action4());
    
    }
    
    static    Employee emp[]=new Employee[5];
   public static int search(String s)
  {
  	for(int i=0;i<Employee.count;i++)
  	{
  		if(emp[i].getFirstName().equals(s))
  			return i;
  	}
  	
  	return -1;
   
    
}


    static class Action1 implements ActionListener{
        
        public void actionPerformed(ActionEvent e){
            
          HireEmp h=new HireEmp();
            
           
            

        }
}
    static class Action2 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
            
            ViewDetails v=new ViewDetails();
}
}
        static class Action3 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
            
            ChangeIncome i=new ChangeIncome();
        }
    }
        
        static class Action4 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
            
            System.exit(0);
        }    
        
            
        
    
        
            
}
}


I hope Iam making sense. Thanks again.
Was This Post Helpful? 0
  • +
  • -

#7 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: CLASS is not abstract and does not override abstract method error

Posted 26 May 2010 - 02:48 PM

I am not sure what you mean by:

Quote

I have 2 classes. The main class called 'Group13ProjectMGTsystem' impliments the 'Property UI' class when the Jbutton is pressed

when implementing an interface, you must override all it's methods.
the interface ActionListener contains one methd:
public void actionPerformed(ActionEvent e)

all classes that override that interface MUST override the actionPerformed method.
Was This Post Helpful? 0
  • +
  • -

#8 nods  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 68
  • Joined: 09-December 09

Re: CLASS is not abstract and does not override abstract method error

Posted 26 May 2010 - 04:26 PM

sorry i but am already using the
public void actionPerformed(ActionEvent e)
and still cant get it to work. this has got me confused. Could another class in the program be affecting it?

many thanks

nods
Was This Post Helpful? 0
  • +
  • -

#9 m-e-g-a-z  Icon User is offline

  • Winning
  • member icon


Reputation: 496
  • View blog
  • Posts: 1,453
  • Joined: 19-October 09

Re: CLASS is not abstract and does not override abstract method error

Posted 26 May 2010 - 04:46 PM

Saying 'still cant get it to work' isn't going to help neither you or us.
What error are you getting now?
Could you please post your revised code so we can see whats exactly wrong.
Was This Post Helpful? 0
  • +
  • -

#10 nods  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 68
  • Joined: 09-December 09

Re: CLASS is not abstract and does not override abstract method error

Posted 26 May 2010 - 05:14 PM

At the moment I am not getting any error messages. However nth happens when the buttons are pressed.
when i add the'implimentsActionlistener' at the end of 'extends JFrame' to activate the listener i get the 'CLASS is not abstract and does not override abstract method error'.

Hope it makes more sense now. and again thanks for your help. Code is below

/**
 *
 *
 * 
 *
 */import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Group13PropertyMGTsystem extends JFrame{
public static void main(String[] args) {

    JFrame frame = new JFrame("Group13PropertyMGTsystem");
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(800,400);
    JPanel panel1 = new JPanel();
    frame.add(panel1);
    JButton button1 = new JButton("Property Maintenance");
    panel1.add(button1);
    button1.addActionListener(new Action1());
    JButton button2 = new JButton("Client Maintenance");
    panel1.add(button2);
    button2.addActionListener(new Action2());
    JButton button3 = new JButton("Tennant Maintenance");
    panel1.add(button3);
    button3.addActionListener(new Action3());
    JButton button4 = new JButton("Payments");
    panel1.add(button4);
    button4.addActionListener(new Action4());
    JButton button5 = new JButton("Invoice");
    panel1.add(button5);
    button5.addActionListener(new Action5());
    
    
   
    
}
    static class Action1 implements ActionListener{
        
        public void actionPerformed(ActionEvent e){
            
          PropertyUI p=new PropertyUI();
            
           
            

        }
}
    static class Action2 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
           
            
}
}
        static class Action3 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
            
            
        }
    }
        
        static class Action4 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
           
            
        }    
        }
        static class Action5 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
            
            
        }
    
        
            
}
}


Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: CLASS is not abstract and does not override abstract method error

Posted 26 May 2010 - 05:41 PM

This is not the way it should be done

Code in the static main() method should be reduced to the minimum... just to instantiate a new Object

as your class is already a JFrame no need to create a JFrame inside it

Avoid static classes and methods they usually show a bad design
that will do the trick, or achieve what you want to do, I think

public class Group13PropertyMGTsystem extends JFrame implements ActionListener { 

	JButton button1, button2, button3, button4, button5;

	Group13PropertyMGTsystem() {
		setTitle("Group13PropertyMGTsystem");

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
		setSize(800,400); 
		JPanel panel1 = new JPanel(); 
		add(panel1); 
		button1 = new JButton("Property Maintenance"); 
		panel1.add(button1); 
		button1.addActionListener(this); 
		button2 = new JButton("Client Maintenance"); 
		panel1.add(button2); 
		button2.addActionListener(this); 
		button3 = new JButton("Tennant Maintenance"); 
		panel1.add(button3); 
		button3.addActionListener(this); 
		button4 = new JButton("Payments"); 
		panel1.add(button4); 
		button4.addActionListener(this); 
		button5 = new JButton("Invoice"); 
		panel1.add(button5); 
		button5.addActionListener(this); 
		
		add(panel1);
	}
	
	public void actionPerformed(ActionEvent e) {
		Object o = e.getSource();
		if(o == button1)
			System.out.println("Button1 was pressed");
		else if(o == button2)
			System.out.println("Button2 was pressed");
		else if(o == button3)
			System.out.println("Button3 was pressed");
		else if(o == button4)
			System.out.println("Button4 was pressed");
		else if(o == button5)
			System.out.println("Button5 was pressed");
	}	

	public static void main(String[] args) { 

		Group13PropertyMGTsystem frame = new  Group13PropertyMGTsystem();    
		frame.setVisible(true); 
	} 
}


Was This Post Helpful? 2
  • +
  • -

#12 nods  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 68
  • Joined: 09-December 09

Re: CLASS is not abstract and does not override abstract method error

Posted 26 May 2010 - 05:56 PM

wow thats so much easier than th ecode I wrote, Thx a million.

just one question.

how do I replace your

System.out.println("Button1 was pressed"); 


with

PropertyUI p=new PropertyUI(); 


I am getting a 'not a statment error'.
Was This Post Helpful? 0
  • +
  • -

#13 m-e-g-a-z  Icon User is offline

  • Winning
  • member icon


Reputation: 496
  • View blog
  • Posts: 1,453
  • Joined: 19-October 09

Re: CLASS is not abstract and does not override abstract method error

Posted 26 May 2010 - 06:05 PM

Well its a bad design to have two Frames especially with both of them Active, that will happen if you instantiate PropertyUI.
Was This Post Helpful? 0
  • +
  • -

#14 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: CLASS is not abstract and does not override abstract method error

Posted 26 May 2010 - 06:06 PM

Cannot probably done on in a single line if statement
What will you done with your p object ? it will vanish right away
		if(o == button1)
			PropertyUI p = new PropertyUI();


but that will work
		if(o == button1) {
			PropertyUI p = new PropertyUI();
		}


Was This Post Helpful? 1
  • +
  • -

#15 m-e-g-a-z  Icon User is offline

  • Winning
  • member icon


Reputation: 496
  • View blog
  • Posts: 1,453
  • Joined: 19-October 09

Re: CLASS is not abstract and does not override abstract method error

Posted 26 May 2010 - 06:35 PM

Looking at the PropertyUI class, I've noticed that you create most of the GUI in the main() which pbl pointed out in the previous post for the other class.

You also have no constructor, so when you instantiate the Object within the ActionEvent() method, nothing will happen.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

//You extend frame no reason for instantiating a new JFrame
public class PropertyUI extends JFrame {

//Constructor 
 public PropertyUI(){
    super("Group13PropertyMGTsystem");
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(800,400);
    JPanel panel1 = new JPanel();
    add(panel1);
    JButton button1 = new JButton("Add  New Property");
    panel1.add(button1);
    button1.addActionListener(new Action1());
    JButton button2 = new JButton("Vew Property Details");
    panel1.add(button2);
    button2.addActionListener(new Action2());
    JButton button3 = new JButton("Ammend Property Details");
    panel1.add(button3);
    button3.addActionListener(new Action3());
    JButton button4 = new JButton("Close");
    panel1.add(button4);
    button4.addActionListener(new Action4());
    
    }
    

    static class Action1 implements ActionListener{
        
        public void actionPerformed(ActionEvent e){
            
          AddProperty a=new AddProperty(); ///******ERROR ON THIS LINE****
            
           
            

        }
}
    static class Action2 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
                   
}
}
        static class Action3 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
            
          
        }
    }
        
        static class Action4 implements ActionListener{
        
        public void actionPerformed (ActionEvent e){
            
            System.exit(0);
        }    
           
}
/* run  new instance of PropertyUI within the main()
        public static void main (String [] args){
        	new PropertyUI();
        }
*/
}



So when you are instantiating the PropertyUI in the ActionEvent, make sure the other Frame's visibility is false.

 if(o == button1) {
                this.setVisible(false);        
                PropertyUI p = new PropertyUI();
                }



Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2