Reputation: 1
Okay so I'm making a book store application using a GUI, the main screen shows a list that is populated from an array list I have made. The list shows books in stock so has "Book Title, Author, ISBN ETC ETC. What I have done is add a "Add Book" form. Now that will need to let the user fill in some text fields with information about a book and click "add". The information from the text fields will then be added to the stock list.
Is this code alone the right lines for what needs to be done?
list.add(input.getText());
Or is it far more complex than this?
Many thanks
Upvotes: 0
Views: 1429
Reputation: 879
Assuming that you have the following constructor:
public Book(String title, String author, String isbn, etc){
this.title = title;
this.author = author;
this.isbn = isbn;
etc
}
As far as I understood your list should handle Book objects. Therefore, when the Add button is pressed, you need an action performed event that will do the following.
Book bookName = new Book(titleInput.getText(),authorInput.getText(),isbnInput.getText(),etc);
list.add(bookName);
Note that, each textfield has a specific name that refers to it.
Finally, when you want to retrieve this information you should use the get(Object o) method of the list and then use the getter method of the specific attribute.
Upvotes: 1