compilation error message[I do not understand this error message,please help!]

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • babs115
    New Member
    • Jun 2015
    • 18

    compilation error message[I do not understand this error message,please help!]

    ERROR
    [Bookshop is not an abstract and does not override abstract method actionPerformed (java.awt.event .ActionEvent)in java.awt.event. ActionListener]

    Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Bookshop extends JFrame implements ActionListener
    {
     
     JTextField productIdText;
     JTextField productNameText;
     JTextField productCostText;
     JTextField productyearOfPublicationText;
     JTextField productpublishingHouseText;
    
     JButton submit;
     Product [] productList = new Product [100];//productList array to store Person objects
     int numberOfproduct = 0;// counter to know how many objects are in the array
    public static void main(String []args)
    { 
       new Bookshop();
    }
    
    class Product
    {
       private int productId;
       private String productName;
       private double cost;
       private int yearOfPublication;
       private String publishingHouse;
    
    
    public Product(int productId,String productName,double cost,int yearOfPublication,String publishingHouse)
    {
       this.productId = productId;
       this.productName = productName;
       this.cost = cost;
       this.yearOfPublication = yearOfPublication;
       this.publishingHouse = publishingHouse;
       
      
            setSize(400,400);
            setLayout(new FlowLayout());
            
            productIdText = new JTextField(5);        
            add(productIdText);
            
            productNameText = new JTextField(5);        
            add(productNameText);
            
            productCostText = new JTextField(5);        
            add(productCostText);
            
            productyearOfPublicationText = new JTextField(5);        
            add(productyearOfPublicationText);
            
            productpublishingHouseText = new JTextField(5);        
            add(productpublishingHouseText);
            
            submit = new JButton("press");
            submit.addActionListener(this);
            add(submit);
            
        
            setVisible(true);
        
    }
    
    public void actionPerformed(ActionEvent e)
    {
            if(e.getSource() == submit)// get the data from textfields
            {
                int id =  Integer.parseInt(productIdText.getText());
                String name = productNameText.getText();
                double cost = productCostText.getText();
                int yearOfPublication = productyearOfPublicationText.getText();
                String publishingHouse = productpublishingHouseText.getText();
                //System.out.println(id);
                //System.out.println(name);
                
                // put new object into array
                productList[numberOfProduct] = new Product(id,name,cost,yearOfPublication,publishingHouse);
                numberOfProduct++;
            }
        
        }
    
    public void setSize(int x,int y)
    {
    }
    
    public void setproductIdText(int productIdText)
    {
     this.productIdText=productIdText;
    }
    
    public void setproductNameText(String productNameText)
    {
      this.productNameText = productNameText;
    }
    public void setId(int productId)
       {
         this.productId = productId;
       }
       
    public int getproductId()
       {
           return productId;
       }
    public void setproductName(String productName)
       {
         this.productName = productName;
       }
       
    public String getproductName()
       {
           return productName;
       }
       
    public void setcost(double cost)
       {
         this.cost = cost;
       }
       
    public double getcost()
       {
           return cost;
       }
       
    public void setyearOfPublication(int yearOfPublication)
       {
         this.yearOfPublication = yearOfPublication;
       }
       
    public int getyearOfPublication()
       {
           return yearOfPublication;
       }
       
    public void setpublishingHouse(String publishingHouse)
       {
         this.publishingHouse = publishingHouse;
       }
       
    public String getpublishingHouse()
       {
           return publishingHouse;
       }
    }
    
    class Book extends Product
    {
     private String author;
     private int isbn;
     private int numberOfPages;
    
    
    public Book(String author, int isbn, int numberOfPages, int productId, String productName, double cost,
                           int yearOfPublication, String publishingHouse)
        {
         super(productId,productName,cost,yearOfPublication,publishingHouse);      
         this.author = author;
         this.isbn = isbn;
         this.numberOfPages = numberOfPages; 
        }
    }
    
    class Software extends Product
    {
     private int RAM;
     private int processor;
     
     
     
     public Software(int ram,int processor,int productId, String productName, double cost,
                      int yearOfPublication, String publishingHouse)
         {
             super(productId,productName,cost,yearOfPublication,publishingHouse);      
             this.ram = ram;
             this.processor = processor; 
         }
         
    }
     
    }
    error section is marked in the attachment.than k in advance.
    Attached Files
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    The error essage means that your class Bookshop needs the method actionPerformed , but you did not provide one. Instead, you provided one for class Product that does not need one. So just move the method actionPerformed to the right class.

    BookShop extends JFrame, and jFrame defines the abstract method actionPerformed . So the error message says that all classes that extend JFrame must either define an own abstract method actionPerformed , or implement this method.

    Comment

    • babs115
      New Member
      • Jun 2015
      • 18

      #3
      Thanks a million.
      Your are great.

      Comment

      Working...