You interface is a little clunky. You could use a JTextField
for the name a JSpinner
for the score and JButton
to insert the values into the linked list, but that's just me...
Overall, the information is getting to the JTextArea
just fine, the formatting is wrong.
To start with, construct the listView
with rows
and columns
listView = new JTextArea(5, 20);
This will make the JTextArea
occupy more space by default.
Second, place the JTextArea
in a JScrollPane
, this will allow the content to scroll automatically beyond the viewable size of the window, this means you can get rid of the pack
in the ActionListener
Third, change the toString
method in GameList
. Having to separate loops doesn't seem to make sense, instead, include all the information you need in each iteration of a single loop, for example...
public String toString() {
StringBuilder strBuilder = new StringBuilder();
Node p = first;
//Node r = first;
while (p != null) {
strBuilder.append(p.name).append(" ");
strBuilder.append(p.score).append("\n");
p = p.next;
}
//while (r != null) {
// strBuilder.append(r.score).append("\n");
// r = r.next;
//}
return strBuilder.toString();
}