Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Applets and Threads

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone explain to me if the following code should work.
Its just a simple test with threads and Applets.
Thread 1 prints date and time to Applet.
Thread 2 prints date and time to console (am using Jbuilder)
When I run this in Jbuilder there is no output displayed on the applet, but there date is updated on the console.
If I put System.out.println()s on either side of repaint() they get printed in a loop, which says to me that repaint is being called but for some reason never gets as far as calling paint.
Am i missing something fundamental or should this work?
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Dermot
In the code you have line that says,
work.run();
is a problem because,
1. if we call run() method directly on a thread it doesn't start a thread but instead just results into a method call. That line should be - work.start()
2. now, that run() is in infinite loop and as its a method call it hogs the JVM due to which the Applet UI Thread never gets a chance to paint data on the applet screen even if it is generating that data by calling repaint()
So, work.start() should do magic for you. Otherwise I don't see any problem.
Regards
Maulin
 
Dermot Curley
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Maulin, it works perfect
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic