Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Use same object on different components

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an instance of a label that displays the current system time. I want to pass this to 3 different components to display on all of them. However, it only shows the clock on the last component it is added to. I don't want to create 3 different instances of this clock, because then I would have to create 3 separate threads for the time, resulting in the clocks not being identical.

Can anyone tell me how to display the same object on three different components?

Thanks!
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A component can only have 1 parent. So the only thing you would be able to do is abstract the actual clock (non GUI) away from the JLabel. Create as many JLabel instances as you want and update each of them with the clock value, which you can make static so that there is only one in memory.

Think MVC. The JLabel is the view. The clock is the model.
[ October 08, 2004: Message edited by: Gregg Bolinger ]
 
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic