Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

From Queue to JList (separate classes)  RSS feed

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
* I want to create a Java Queue in a separate “Queue class”.

* Then from another “GUI class” I want to create a JList that gets the content of that queue and show it on the screen.

My failed  attempt to create the JList looks like this (from the "GUI class"):



Here’s my “Queue class”:    
 
Marshal
Posts: 62263
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What sort of parameters does a JList take for its constructor? Is it List or Vector or something? You cannot therefore directly use a Queue, but you can take the elements from the Queue with its iterator. I tthink you should pass that information to a model; look for classes called XXXListModel.
 
Master Rancher
Posts: 933
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The constructor expect an array, not a qeue and you never initialize your qeue, I don't see an instance of you Kö1.Class, nor I see elements being added to the qeue
If you change to
and change your getter, you can then do
 
Daniel Andersson
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:What sort of parameters does a JList take for its constructor? Is it List or Vector or something? You cannot therefore directly use a Queue, but you can take the elements from the Queue with its iterator. I tthink you should pass that information to a model; look for classes called XXXListModel.


I think a ”DefaultList- Model” .

I was confused I thought my assignment required me not to create a   ”DefaultList- Model” in the “Gui” class. But now I see that it's allowed.

So my guess is that I could use a “getDefaultListModel” in the queue 
class or something.


Daniel Demesmaecker wrote:The constructor expect an array, not a qeue and you never initialize your qeue, I don't see an instance of you Kö1.Class, nor I see elements being added to the qeue
If you change to
and change your getter, you can then do


Ok thanks for the information! Might be very useful
 
Campbell Ritchie
Marshal
Posts: 62263
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:. . .

But doesn't that expose implementation details? Maybe it would  be better to have a method returning an array directly.

Search for “Law of Demeter”.
 
Daniel Demesmaecker
Master Rancher
Posts: 933
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would, I'm not even sure why he's set on using a qeue, I would never do that in this case
 
Campbell Ritchie
Marshal
Posts: 62263
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:. . . I'm not even sure why he's set on using a qeue . . .

Maybe he has an assignment requiring him to use a Queue. Otherwise it is, as you say, a very strange requirement.
 
Trust God, but always tether your camel... to this tiny ad.
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!