By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,551 Members | 2,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,551 IT Pros & Developers. It's quick & easy.

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

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

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. public class Bookshop extends JFrame implements ActionListener
  5. {
  6.  
  7.  JTextField productIdText;
  8.  JTextField productNameText;
  9.  JTextField productCostText;
  10.  JTextField productyearOfPublicationText;
  11.  JTextField productpublishingHouseText;
  12.  
  13.  JButton submit;
  14.  Product [] productList = new Product [100];//productList array to store Person objects
  15.  int numberOfproduct = 0;// counter to know how many objects are in the array
  16. public static void main(String []args)
  17.    new Bookshop();
  18. }
  19.  
  20. class Product
  21. {
  22.    private int productId;
  23.    private String productName;
  24.    private double cost;
  25.    private int yearOfPublication;
  26.    private String publishingHouse;
  27.  
  28.  
  29. public Product(int productId,String productName,double cost,int yearOfPublication,String publishingHouse)
  30. {
  31.    this.productId = productId;
  32.    this.productName = productName;
  33.    this.cost = cost;
  34.    this.yearOfPublication = yearOfPublication;
  35.    this.publishingHouse = publishingHouse;
  36.  
  37.  
  38.         setSize(400,400);
  39.         setLayout(new FlowLayout());
  40.  
  41.         productIdText = new JTextField(5);        
  42.         add(productIdText);
  43.  
  44.         productNameText = new JTextField(5);        
  45.         add(productNameText);
  46.  
  47.         productCostText = new JTextField(5);        
  48.         add(productCostText);
  49.  
  50.         productyearOfPublicationText = new JTextField(5);        
  51.         add(productyearOfPublicationText);
  52.  
  53.         productpublishingHouseText = new JTextField(5);        
  54.         add(productpublishingHouseText);
  55.  
  56.         submit = new JButton("press");
  57.         submit.addActionListener(this);
  58.         add(submit);
  59.  
  60.  
  61.         setVisible(true);
  62.  
  63. }
  64.  
  65. public void actionPerformed(ActionEvent e)
  66. {
  67.         if(e.getSource() == submit)// get the data from textfields
  68.         {
  69.             int id =  Integer.parseInt(productIdText.getText());
  70.             String name = productNameText.getText();
  71.             double cost = productCostText.getText();
  72.             int yearOfPublication = productyearOfPublicationText.getText();
  73.             String publishingHouse = productpublishingHouseText.getText();
  74.             //System.out.println(id);
  75.             //System.out.println(name);
  76.  
  77.             // put new object into array
  78.             productList[numberOfProduct] = new Product(id,name,cost,yearOfPublication,publishingHouse);
  79.             numberOfProduct++;
  80.         }
  81.  
  82.     }
  83.  
  84. public void setSize(int x,int y)
  85. {
  86. }
  87.  
  88. public void setproductIdText(int productIdText)
  89. {
  90.  this.productIdText=productIdText;
  91. }
  92.  
  93. public void setproductNameText(String productNameText)
  94. {
  95.   this.productNameText = productNameText;
  96. }
  97. public void setId(int productId)
  98.    {
  99.      this.productId = productId;
  100.    }
  101.  
  102. public int getproductId()
  103.    {
  104.        return productId;
  105.    }
  106. public void setproductName(String productName)
  107.    {
  108.      this.productName = productName;
  109.    }
  110.  
  111. public String getproductName()
  112.    {
  113.        return productName;
  114.    }
  115.  
  116. public void setcost(double cost)
  117.    {
  118.      this.cost = cost;
  119.    }
  120.  
  121. public double getcost()
  122.    {
  123.        return cost;
  124.    }
  125.  
  126. public void setyearOfPublication(int yearOfPublication)
  127.    {
  128.      this.yearOfPublication = yearOfPublication;
  129.    }
  130.  
  131. public int getyearOfPublication()
  132.    {
  133.        return yearOfPublication;
  134.    }
  135.  
  136. public void setpublishingHouse(String publishingHouse)
  137.    {
  138.      this.publishingHouse = publishingHouse;
  139.    }
  140.  
  141. public String getpublishingHouse()
  142.    {
  143.        return publishingHouse;
  144.    }
  145. }
  146.  
  147. class Book extends Product
  148. {
  149.  private String author;
  150.  private int isbn;
  151.  private int numberOfPages;
  152.  
  153.  
  154. public Book(String author, int isbn, int numberOfPages, int productId, String productName, double cost,
  155.                        int yearOfPublication, String publishingHouse)
  156.     {
  157.      super(productId,productName,cost,yearOfPublication,publishingHouse);      
  158.      this.author = author;
  159.      this.isbn = isbn;
  160.      this.numberOfPages = numberOfPages; 
  161.     }
  162. }
  163.  
  164. class Software extends Product
  165. {
  166.  private int RAM;
  167.  private int processor;
  168.  
  169.  
  170.  
  171.  public Software(int ram,int processor,int productId, String productName, double cost,
  172.                   int yearOfPublication, String publishingHouse)
  173.      {
  174.          super(productId,productName,cost,yearOfPublication,publishingHouse);      
  175.          this.ram = ram;
  176.          this.processor = processor; 
  177.      }
  178.  
  179. }
  180.  
  181. }
  182.  
error section is marked in the attachment.thank in advance.
Attached Files
File Type: docx assign.docx (287.0 KB, 240 views)
Jul 13 '15 #1

✓ answered by chaarmann

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.

Share this Question
Share on Google+
2 Replies


Expert 100+
P: 785
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.
Jul 13 '15 #2

P: 18
Thanks a million.
Your are great.
Jul 13 '15 #3

Post your reply

Sign in to post your reply or Sign up for a free account.