Virtual Library Project

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asmohamed12
    New Member
    • Feb 2008
    • 4

    Virtual Library Project

    So basically, this is my project:

    * Write a LibraryManager class that provides a GUI application to add, check out, look up the status of, and return books in a library.

    The GUI compiles and executes perfectly. I just need to finish the code for the LibraryBook in order to make the GUI function correctly.
    -------------------------------------
    So here is what I've gotten so far. I'm having trouble trying to write the code to actually add the books to a Library(ArrayLi st). Do I need to create an arrayList first, if so, how do I do so? I have my GUI setup, I just need to figure out the code to go into the MouseClicked part as well as the rest of the code. I've gotten a good portion of the code written, I'm just not exactly sure how to put it all together. I'm obviously a novice, but this doesn't seem too difficult. Any help would be gladly appreciated. Thanks.

    [SIZE=4]GUI[/SIZE]
    import java.awt.*;
    import java.awt.event. *;
    import javax.swing.*;
    import javax.swing.bor der.*;
    import java.io.*;
    import java.util.Strin gTokenizer;
    import java.util.Array List;
    import java.util.*;

    public class LibraryManager extends JFrame implements LibraryBook
    {
    private JButton add, checkOut, status, returnBook;
    private JTextField inputBox, totalBox;
    private JLabel inputText;
    private String theHolder, dueDate;
    private String theISBN;

    public LibraryManager ()
    {
    setDefaultClose Operation(EXIT_ ON_CLOSE);
    setTitle("Virtu al Library");
    setResizable(fa lse);
    Container pane = getContentPane( );
    pane.setLayout( new GridLayout(3,1) );

    JPanel inputPane = new JPanel();
    inputText = new JLabel("ISBN:") ;
    inputPane.add(i nputText);
    inputBox = new JTextField(30);
    inputPane.add(i nputBox);
    pane.add(inputP ane);

    JPanel buttons = new JPanel();
    add = new JButton("Add");
    buttons.add(add );
    checkOut = new JButton("Check Out");
    buttons.add(che ckOut);
    status = new JButton("Status ");
    buttons.add(sta tus);
    returnBook= new JButton("Return Book");
    buttons.add(ret urnBook);
    pane.add(button s);

    pack();

    }






    public void mouseClicked(Mo useEvent e)
    {
    }
    public void mouseEntered(Mo useEvent e)
    {
    }
    public void mouseExited(Mou seEvent e)
    {
    }
    public void mousePressed(Mo useEvent e)
    {
    }
    public void mouseReleased(M ouseEvent e)
    {
    }


    public static void main(String[] args)
    {
    LibraryManager lm = new LibraryManager( );
    lm.setVisible(t rue);
    }
    }
    -----------------------------------------------------
    [SIZE=4]LibraryBook[/SIZE]

    import java.util.*;
    import java.text.*;


    public interface LibraryBook
    {
    private String title, theHolder, isbn;
    private GregorianCalend ar dueDate;


    public LibraryBook(Str ing t, String i)
    {
    title = t;
    isbn = i;
    }

    public String getTitle()
    {
    return title;
    }

    public String getHolder()
    {
    return theHolder;
    }

    public GregorianCalend ar getDueDate()
    {
    return dueDate;
    }

    public String getISBN()
    {
    return isbn;
    }

    public void checkIn()
    {
    theHolder = null;
    dueDate = null;
    }

    public boolean checkOut(String holder)
    {
    if (theHolder == null)
    {
    theHolder = holder;
    return true;
    }
    return false;
    }

    }
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    I'm confused: is LibraryBook an interface or a class?

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      Please enclose your posted code in [code] tags (See How to Ask a Question).

      This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

      Please use [code] tags in future.

      MODERATOR

      Comment

      • asmohamed12
        New Member
        • Feb 2008
        • 4

        #4
        LibraryBook is actually a class, I can't find the edit button to change that as well as adding the (code) (/code) tags, I'll be sure to use them for future reference

        Comment

        • Laharl
          Recognized Expert Contributor
          • Sep 2007
          • 849

          #5
          You should change LibraryBook to a class rather than an interface. As it is, you can't declare any objects of the interface because that's what an interface is. Thus, your code won't work since you can't have any LibraryBooks to work with unless you have some subclasses written that are actually classes.

          Comment

          • BigDaddyLH
            Recognized Expert Top Contributor
            • Dec 2007
            • 1216

            #6
            If LibraryBook is a classs, then you can't do this:

            [CODE=Java]public class LibraryManager extends JFrame implements LibraryBook[/CODE]

            Even if it were an interface, it doesn't make sense to say "A Library manager is a library book". Perhaps "A Library manager knows library books".

            Does that make sense to you?

            Comment

            • asmohamed12
              New Member
              • Feb 2008
              • 4

              #7
              So I'll just make LibraryBook a class and put it inside of LibraryManger.

              I still am having trouble actually creating books and having the functions implemented to do the actions necessary. I believe I need to use some sort of ArrayList, but not sure how to do so, any suggestions?

              Comment

              • BigDaddyLH
                Recognized Expert Top Contributor
                • Dec 2007
                • 1216

                #8
                Originally posted by asmohamed12
                So I'll just make LibraryBook a class and put it inside of LibraryManger.

                I still am having trouble actually creating books and having the functions implemented to do the actions necessary. I believe I need to use some sort of ArrayList, but not sure how to do so, any suggestions?
                Lists and other collections are easy to use. I suggest you take the Sun tutorial on the collection framework: http://java.sun.com/docs/books/tutor...ons/index.html

                Comment

                • asmohamed12
                  New Member
                  • Feb 2008
                  • 4

                  #9
                  Thank you for your help, success....

                  Comment

                  Working...