Within my Java project I have a class
for a Doubly Linked List, it runs fine putting output to the console window but I was wondering how should I go about getting the output onto a JList
of another JFrame
I have created?
Cheers

- 168,117
- 40
- 217
- 433

- 11
- 1
-
Callbacks, my friend, callbacks. – Johannes Kuhn Apr 25 '20 at 15:22
1 Answers
Since your class
for your linked list does output to the console, the first thing you need to learn is to try and separate your concerns. Your linked list may or may not be outputted at certain method calls and may or may not be outputted to the console or your JList
. Since you may intend (which already happened in your case) to reuse your doubly linked list in different use-cases, you need to implement your class
in a very agnostic manner, without any assumptions about outputting it on the console.
Now, what should your doubly linked list support in order to ensure that it will work in separate environments:
- instantiation
- element adding
- element removal
- element iteration using a callback
Take a look here for examples of callback: Callback functions in Java
Now, if you need to use your class at a console application or a swing application, you can specify a callback and call the element iteration.

- 64,414
- 37
- 100
- 175