3

I am fairly new to Java and programming and want some advice on this test application I want to write.

The general Idea is that it will contain a list of books with a Title, Author, Date stamp and a read or not status.

The date stamp must apply when then read status becomes true.

It will have a GUI that displays the books in alphabetical order in a table format. If possible, I want the column names to be filterable, i.e if you click title it should sort by title, click again and it sorts in descending order. Likewise with author and status.

I want to have a search field that will be able to search books based on title and author. I also want to be able to add books by clicking a button that brings up a pop up window to enter Title, Author, and read status.

The application will run on a PC and thus I think it will be fine to store state by serializing.

I please need advice on a few elements, my plan is to:

  • Write the Book class

    Create it's fields, constructors, getters and setters etc.

  • Write the Library class

    Contains a list (what would be best to use here? ArrayList etc?) of the books in the library the worker class that will build the GUI, read in the objects and populate the Library to be used for the table information. I am sketchy on building a table like this, would I use JTable?

One column must be a check box with the status, which can be clicked and a pop up confirming to change the status.

I am sure I will have more questions once I have feedback :) thanks for any advice.

J.A.I.L.
  • 10,644
  • 4
  • 37
  • 50
user1808348
  • 79
  • 1
  • 1
  • 4
  • 1
    Till now what you have in mind is fine. First implement it then think further. – Rohit Jain Nov 08 '12 at 06:50
  • 1
    Use *interfaces*. For your `Library` class I would use a [`Collection`](http://docs.oracle.com/javase/6/docs/api/java/util/Collection.html). I you whink there shouldn't exist duplicate `Book` instances, then go for a ['Set'](http://docs.oracle.com/javase/6/docs/api/java/util/Set.html) (a subclass of `Collection` with no duplicate items). As instantiation for the `Collection` you can use `ArrayList` or `LinkedList`. As for the `Set`; `TreeSet`, `HashSet` or `LinkedHashSet`. – J.A.I.L. Nov 08 '12 at 07:49
  • Thanks so far, for the JTABLE, how can i make it sort by selecting column? also how can I get the objects from the library collection into a multidimensional array to populate the table? thanks for advice. – user1808348 Nov 08 '12 at 08:41
  • ok the sort via column I figured out: bookTable.setAutoCreateRowSorter(true); – user1808348 Nov 08 '12 at 08:56
  • welcome to SO :-) Just: your question is overly broad and not actually the type of questions that are encouraged here, mainly because they are not answerable. Please read [the faq for details](http://stackoverflow.com/questions/how-to-ask). As to how-to proceed: separate out smaller scope task from your master plan, tackle those concretely in code and ask concrete questions when stuck. And don't forget to read up on the basice, f.i. in the online tutorial referenced in the swing tag wiki. – kleopatra Nov 08 '12 at 09:06
  • thanks and apologies I should have broken it into smaller issues. – user1808348 Nov 08 '12 at 09:37
  • 1
    There's a check box example [here](http://stackoverflow.com/a/7920159/230513) – trashgod Nov 08 '12 at 13:45

1 Answers1

0

[I have created a rough draft of solution, take a look and improve as required][1]

[1]: http://code.google.com/p/booklist-jtable/downloads/list

  • thanks, very nice although not 100% what I am looking for, also I would like to write most of the code myself but well done. I have almost everything working. I have extended DefaultTable model, override the isCellEditable and getColumnClass methods and now my table has check boxes where I want. The issue I now have is that I need it to actually affect that objects state. So if I check a box it must change that field to true and update the table view. any advice? – user1808348 Nov 12 '12 at 05:42
  • it would help if you post your code. I think you could use action handler and inside that handler's method, update the state using getter/setter. – insufferableKnowItAll Jan 06 '13 at 21:36