Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applets and Threads

 
Dermot Curley
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?
 
Maulin Vasavada
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic