473,396 Members | 2,061 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,396 software developers and data experts.

constructor Book in class Book cannot be applied to this given type[Need help]

18
I do not know how to go further from here, please help.
[constructor Book in class Book cannot be applied to this given type]I attached a picture of the area of concern.thanks


Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.io.*;
  3. import java.util.*;
  4. import java.text.*;
  5. import javax.swing.*;
  6. import java.awt.event.*;
  7. import javax.imageio.ImageIO;
  8. import java.awt.image.BufferedImage;
  9. import net.miginfocom.swing.*;
  10.  
  11. public class AddBooks extends JPanel
  12. {
  13.    static JLabel productId, isbn, bookName, author, numberOfPages, yearOfPublication, publishingHouse, cost;
  14.    static JButton back, addNewBook;
  15.    static JTextField productIdTF, isbnTF, bookNameTF, authorTF, numberOfPagesTF, yearOfPublicationTF, publishingHouseTF, costTF;
  16.    static JPanel mainPanel, buttonsPanel;
  17.    static CardLayout cardLayout;     
  18.    private BufferedImage wallpaper;    
  19.  
  20.    @SuppressWarnings("unchecked") //  gets rid of the unchecked or unsafe warning
  21.    public AddBooks(){                    
  22.        final String dir = System.getProperty("user.dir"); 
  23.        Color labelColor = new Color(76,0,153);        
  24.        Color textFieldColor = new Color(255,0,0); 
  25.  
  26.         //------------------------     WALLPAPER    ---------------------//
  27.         try {
  28.           wallpaper = ImageIO.read(new File(dir + "/Images/AddBookBG.png"));
  29.         } catch(IOException e) {
  30.           e.printStackTrace();
  31.         }
  32.         //********************  END OF WALLPAPER    ***********************//
  33.  
  34.         setLayout(new MigLayout(""));
  35.  
  36.         productId = new JLabel("ProductId");
  37.         productId.setFont(new Font("Arial Black", Font.PLAIN, 12));
  38.         productId.setForeground(labelColor);
  39.         productIdTF = new JTextField(20); 
  40.         productIdTF.setForeground(textFieldColor);
  41.         productIdTF.setFont(new Font("Arial Black", Font.PLAIN, 14));
  42.  
  43.         isbn = new JLabel("BOOK ISBN");
  44.         isbn.setFont(new Font("Arial Black", Font.PLAIN, 12));
  45.         isbn.setForeground(labelColor);
  46.         isbnTF = new JTextField(20);  
  47.         isbnTF.setForeground(textFieldColor);
  48.         isbnTF.setFont(new Font("Arial Black", Font.PLAIN, 14));
  49.  
  50.         bookName = new JLabel("BOOK NAME");
  51.         bookName.setFont(new Font("Arial Black", Font.PLAIN, 12));
  52.         bookName.setForeground(labelColor);
  53.         bookNameTF = new JTextField(20);
  54.         bookNameTF.setForeground(textFieldColor);
  55.         bookNameTF.setFont(new Font("Arial Black", Font.PLAIN, 14));
  56.  
  57.         author = new JLabel("BOOK AUTHOR");
  58.         author.setFont(new Font("Arial Black", Font.PLAIN, 12));
  59.         author.setForeground(labelColor);
  60.         authorTF = new JTextField(20);
  61.         authorTF.setForeground(textFieldColor);
  62.         authorTF.setFont(new Font("Arial Black", Font.PLAIN, 14));
  63.  
  64.         numberOfPages = new JLabel("No. OF PAGES");
  65.         numberOfPages.setFont(new Font("Arial Black", Font.PLAIN, 12));
  66.         numberOfPages.setForeground(labelColor);
  67.         numberOfPagesTF = new JTextField(20);
  68.         numberOfPagesTF.setForeground(textFieldColor);
  69.         numberOfPagesTF.setFont(new Font("Arial Black", Font.PLAIN, 14));
  70.  
  71.         yearOfPublication = new JLabel("yearOfPublication");
  72.         yearOfPublication.setFont(new Font("Arial Black", Font.PLAIN, 12));
  73.         yearOfPublication.setForeground(labelColor);
  74.         yearOfPublicationTF = new JTextField(20);
  75.         yearOfPublicationTF.setForeground(textFieldColor);
  76.         yearOfPublicationTF.setFont(new Font("Arial Black", Font.PLAIN, 14));
  77.  
  78.         publishingHouse = new JLabel("PUBLISHED publishingHouse");
  79.         publishingHouse.setFont(new Font("Arial Black", Font.PLAIN, 12));
  80.         publishingHouse.setForeground(labelColor);
  81.         publishingHouseTF = new JTextField(20);
  82.         publishingHouseTF.setForeground(textFieldColor);
  83.         publishingHouseTF.setFont(new Font("Arial Black", Font.PLAIN, 14));
  84.  
  85.         cost = new JLabel("PRICE");
  86.         cost.setFont(new Font("Arial Black", Font.PLAIN, 12));
  87.         cost.setForeground(labelColor);                        
  88.         costTF = new JTextField(20);
  89.         costTF.setForeground(textFieldColor);
  90.         costTF.setFont(new Font("Arial Black", Font.PLAIN, 12));
  91.  
  92.  
  93.         back = new JButton("");
  94.         back.setFont(new Font("Arial Black", Font.PLAIN, 10));
  95.         back.setBorder(BorderFactory.createEmptyBorder()); // remove button border   
  96.         back.setContentAreaFilled(false);                // remove the filled area of the button
  97.         back.setIcon(new ImageIcon(dir + "/Images/back.png"));
  98.         back.setRolloverIcon(new ImageIcon (dir + "/Images/backG.png"));// adding roolover image
  99.         back.setVerticalTextPosition(SwingConstants.BOTTOM);    // Setting button text to buttom of the image
  100.         back.setHorizontalTextPosition(SwingConstants.CENTER);  // centerizing the text of the button
  101.  
  102.         addNewBook = new JButton("");
  103.         addNewBook.setFont(new Font("Arial Black", Font.PLAIN, 12));
  104.         addNewBook.setBorder(BorderFactory.createEmptyBorder()); // remove border from button        
  105.         addNewBook.setContentAreaFilled(false);                // remove the filled are from button
  106.         addNewBook.setIcon(new ImageIcon(dir + "/Images/addBK.png"));
  107.         addNewBook.setRolloverIcon(new ImageIcon (dir + "//Images/addBKG.png"));// adding roolover image
  108.         addNewBook.setVerticalTextPosition(SwingConstants.BOTTOM);    // Setting button text to buttom of the image
  109.         addNewBook.setHorizontalTextPosition(SwingConstants.CENTER);  // centerizing the text of the button
  110.          //------------------ END OF CREATING BUTTONS ------------------\\
  111.  
  112.  
  113.          productIdTF.addKeyListener(new KeyAdapter() {
  114.           public void keyTyped(KeyEvent e) {
  115.               char n = e.getKeyChar();
  116.               if (!((n >= '0') && (n <= '9') ||
  117.                  (n == KeyEvent.VK_BACK_SPACE) ||
  118.                  (n == KeyEvent.VK_DELETE))) {                
  119.                 getToolkit().beep();
  120.                 e.consume();
  121.                 JOptionPane.showMessageDialog(null,"Only numbers allowed!", "Info", JOptionPane.YES_NO_OPTION);
  122.               }
  123.            }
  124.         });
  125.         yearOfPublicationTF.addKeyListener(new KeyAdapter() {
  126.           public void keyTyped(KeyEvent e) {
  127.               char n = e.getKeyChar();
  128.               if (!((n >= '0') && (n <= '9') ||
  129.                  (n == KeyEvent.VK_BACK_SPACE) ||
  130.                  (n == KeyEvent.VK_DELETE))) {
  131.                 getToolkit().beep();
  132.                 e.consume();
  133.                 JOptionPane.showMessageDialog(null,"Only yearOfPublication allowed!\ne.g 1990", "Info", JOptionPane.YES_NO_OPTION);
  134.               }
  135.            }
  136.         });
  137.         costTF.addKeyListener(new KeyAdapter() {
  138.           public void keyTyped(KeyEvent e) {
  139.               char n = e.getKeyChar();
  140.               if (!((n >= '0') && (n <= '9') ||
  141.                  (n == KeyEvent.VK_BACK_SPACE) ||
  142.                  (n == KeyEvent.VK_DELETE))) {
  143.                 getToolkit().beep();
  144.                 e.consume();
  145.                 JOptionPane.showMessageDialog(null,"Only numbers allowed!", "Info", JOptionPane.YES_NO_OPTION);
  146.               }
  147.            }
  148.         });
  149.  
  150.  
  151.         back.addActionListener(new ActionListener(){
  152.             public void actionPerformed(ActionEvent arg0){
  153.                 AlphaApp.cardLayout.show(  AlphaApp.cards, "Main Menu");
  154.             }
  155.         });
  156.  
  157.         addNewBook.addActionListener(new ActionListener(){
  158.             public void actionPerformed(ActionEvent arg0){
  159.                 int productID = Integer.parseInt(productIdTF.getText());    
  160.                 String productName = bookNameTF.getText().toUpperCase().trim();                
  161.                 double productCost = Double.parseDouble(costTF.getText());               
  162.                 int productyearOfPublication = Integer.parseInt(yearOfPublicationTF.getText());                 
  163.                 String productpublishingHouse = publishingHouseTF.getText().toUpperCase().trim();
  164.                 String productAuthor = authorTF.getText().toUpperCase().trim();
  165.                 String Isbn = isbnTF.getText().toUpperCase().trim();
  166.                 String numberOfPages = numberOfPagesTF.getText().toUpperCase().trim();                 
  167.  
  168.                 MainMenu.bookList.add(new Book(
  169.                 productID, productName, cost,yearOfPublication, 
  170.                 publishingHouse, author, Isbn, numberOfPages));                
  171.  
  172.                 productIdTF.setText("");
  173.                 isbnTF.setText("");
  174.                 bookNameTF.setText("");
  175.                 authorTF.setText("");
  176.                 numberOfPagesTF.setText("");
  177.                 yearOfPublicationTF.setText("");
  178.                 publishingHouseTF.setText("");
  179.                 costTF.setText("");
  180.                 JOptionPane.showMessageDialog(null, "NEW BOOK ADDED");      
  181.                 AlphaApp.cardLayout.show(AlphaApp.cards, "Main Menu");
  182.             }
  183.         });
  184.  
  185.  
  186.         //****************** ADDING COMPONENT TO PANEL *****************\\        
  187.         add(productIdTF, " sg label, gapTop 140, split 2");    
  188.         add(productIdTF, "sg TF, wrap");
  189.         add(isbn, " sg label, gapTop 10, split 2");    
  190.         add(isbnTF, "sg TF, wrap");
  191.         add(bookName, " sg label, gapTop 10, split 2");        
  192.         add(bookNameTF, "sg TF, wrap");
  193.         add(author, " sg label, gapTop 10, split 2");        
  194.         add(authorTF, "sg TF, wrap");
  195.         add(numOfPages, " sg label, gapTop 10, split 2");        
  196.         add(numOfPagesTF, "sg TF, wrap");       
  197.         add(publishingHouse, " sg label, gapTop 10, split 2");       
  198.         add(publishingHouseTF, "sg TF, wrap");
  199.         add(yearOfPublication, " sg label, gapTop 10, split 2");       
  200.         add(yearOfPublicationTF, "sg TF, wrap");
  201.         add(cost, " sg label, gapTop 10, split 2"); 
  202.         add(costTF, "sg TF, wrap");
  203.  
  204.         add(back, "center, sg a, gapTop 70, gapRight 60, split 2");   
  205.         add(addNewBook, "sg a, gapTop 70, wrap");                               
  206.     } 
  207.  
  208.      @Override
  209.     protected void paintComponent(Graphics g) {
  210.        super.paintComponent(g);
  211.        // paint the background image and scale it to fill the entire space
  212.        g.drawImage(wallpaper, 0, 0, getWidth(), getHeight(), this);
  213.     }   
  214. }
  215.  
Attached Files
File Type: docx Doc1.docx (245.1 KB, 351 views)
Jul 27 '15 #1
3 2096
chaarmann
785 Expert 512MB
I am too afraid of virus to open a word document. And I do not have Microsoft office, but Libre Office and maybe that cannot read it in anyway.

Can you please attach a picture, or much quicker: just tell us the line number in code above where the error happens.
Jul 28 '15 #2
babs115
18
The error is in line 168
Jul 28 '15 #3
chaarmann
785 Expert 512MB
I can't see the bookList object and the MainMenu, but the error says that the "thing" alias "new Book(...)" you have passed into the add() method in "MainMenu.bookList.add(thing)" is not of the correct type. To see the correct type, I need to see the definition of the "bookList" object. Can you please list it? I strongly suspect that you have given a type there which is not a superclass of "Book".
Jul 29 '15 #4

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

Similar topics

5
by: Simon | last post by:
Hi I am trying to produce an update trigger. I understand the concept of delete and insert triggers without a problem. Unfortuantely, the update triggers do not have particularly simple...
1
by: bi | last post by:
hi I am currently getting the following issue with webservices, anyone got any ideas? this only just started happening. a project with an output type of class library cannot be started directly ...
10
by: asnowfall | last post by:
I get following compilation error C3149: 'System::String' : cannot use this type here without a top-level '^'. Could someone explain why I get this error? here is the code... ImageFileData.h...
3
by: Ami | last post by:
Hi All, I want to find at runtime for given class object, if it is a object of given class. For example: I have declared "ClassA" and i have created its instance "instA". Now at run time, how can...
4
by: craig | last post by:
During construction of an object "parent", if you create a subobject that stores a pointer to the parent (through the "this" pointer), will that pointer be valid when the subobject is later called?...
2
by: amily | last post by:
Hi All, I made a page in asp.net to edit information in the database using gridviewcontrol. It was working fine. Then i entered the template column having dropdown list. now the page opens and and i...
3
by: mishink7 | last post by:
i am getting this error error C2662: 'std::vector<_Ty>::push_back' : cannot convert 'this' pointer from 'const std::vector<_Ty>' to 'std::vector<_Ty> &' with and ...
9
by: Simon | last post by:
Hi, I have some old code that I am trying to use in my current project. But my compiler is reporting a memory leak. (it does not tell me where the leak comes from). I have narrowed down the...
0
by: tech | last post by:
Hi, I have developed a little class to help implement dynamic menus in our application which has a UI. This allows our engine to send a MenuItem object to the UI which is an observer of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.