You're question's a bit unclear, but if you want to present the names of the books in a GUI, first you need to give each Book
a name, aka a string representation. Add a name
attribute to Book
with a getName()
method.
Then create a String
array containing the names of the books. You can do that by:
String names = new String[books.length];
for(int i=0; i<names.length; i++){
names[i] = books[i].getName();
}
Then you can input all the names into a JTextArea
, or possibly a JComboBox
if you want users to be able to choose a book.
With a JComboBox
:
JComboBox combo = new JComboBox(names);
panel.add(combo);
With a JTextArea
:
JTextArea textArea = new JTextArea(10,names.length);
textArea.setEditable(false);
for(int i=0; i<names.size; i++){
textArea.append("Book " + i + "#: " + names[i] + "\n");
}
panel.add(textArea);
Hope this helps.