473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Still experiencing error message. PLEASE HELP!

18
ERROR
[method addActionListener in class javax.swing.AbstractButton cannot be applied to giventypes;
requires:java.awt.event.ActionListener found: Bookshop.product
reason: actual argument Bookshop.product cannot be converted to java.awt.event.ActionListener by method invocation conversion]

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

✓ answered by chaarmann

In line 79 you wrote "submit.addActionListener(this);". Here "this" refers to the current class, which is "Product". This current class does not implement ActionListener interface, but "Bookshop" does. So move the whole screen rendering code to the bookshop class.

There is a design confusion between Bookshop and Product. I mean, your bookshop has one screen and many products. But the products themselves never render their own screen each, they only provide their data to the bookshore which is changing its single screen. This single screen is rendered by the bookshop. The bookshop is responsile for getting the product data and filling in the values.
Or do you want to open a new window (and keep it open) each time the user selects a new product? I mean where the data of different products is so different that no common screen is possible? But then you still need to have a start screen owned by the Bookshop where you can select a product, and I would start to implement that first.

1 1315
chaarmann
785 Expert 512MB
In line 79 you wrote "submit.addActionListener(this);". Here "this" refers to the current class, which is "Product". This current class does not implement ActionListener interface, but "Bookshop" does. So move the whole screen rendering code to the bookshop class.

There is a design confusion between Bookshop and Product. I mean, your bookshop has one screen and many products. But the products themselves never render their own screen each, they only provide their data to the bookshore which is changing its single screen. This single screen is rendered by the bookshop. The bookshop is responsile for getting the product data and filling in the values.
Or do you want to open a new window (and keep it open) each time the user selects a new product? I mean where the data of different products is so different that no common screen is possible? But then you still need to have a start screen owned by the Bookshop where you can select a product, and I would start to implement that first.
Jul 13 '15 #2

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

Similar topics

2
by: Hong | last post by:
Hi, I am trying to create a switch but I do not know why I am geting an error message, can someone tell me what is wrong, Error Message; Warning: Unexpected character in input: '\'...
2
by: SoSaucily | last post by:
I am getting the 'partially uploaded file' error with uploads over about 4k-5k. $_FILE = 3. Rackin my brain on this one, any help appreciated. Php.ini - upload_max_filesize=2M -...
2
by: Robert Stearns | last post by:
I don't understand the reference "2" in the following message. There is only a primary key constraint on the named table. It is generated by default and Im not inserting a value for it. SQL0803N...
3
by: N. Graves | last post by:
Hello, I don't understand this error message." Error accessing File. Network Connection may have been lost." I'm not using any network connection for the database. In the VBA editor is goes...
3
by: Harry | last post by:
OS: Winxp sp2 Visual Studio 2005 Beta 1 Added Files: dotnetfx sdkFramework1.1 ErrrorMessages: Warning 1 The referenced component 'OpenNETCF' could not be found. Warning 2 Couldn't...
1
by: Rafael Tejera | last post by:
I'm receiving this error message. An unhandled exception of type 'System.Security.SecurityException' occurred in system.data.dll Additional information: Request for the permission of type...
2
by: bananna77 | last post by:
In Access'97, I am currently trying to run a Select query, which I normally run every week, without problem, until now. I am currently getting the following error message; The Microsoft Jet...
7
by: teddarr | last post by:
I have an assignment I've been working on for a few days now. I need some help with the last detail. The program is supposed to create 5 objects with varying floating-point parameter lists. The...
6
by: phiefer3 | last post by:
Ok, First of all, I'm using Microsoft Visual Studio 2005, and I've been getting this problem when making c++ projects starting from an empty project. I haven't tried other project types yet, so I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.