• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with classes

 
tyler jones
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to write a class that creates an object of another class. When I run my code, I expect to see a messagebox when the timer reaches the time passed in to the object, but it doesn't. I thought maybe it was because the program hit the end of the main method, so I threw in the thread to keep it executing, but it still didn't give me the message box. Can anyone tell me what I'm doing wrong? Thanks.

[ June 03, 2002: Message edited by: Dirk Schreckmann ]
 
Shivaji Marathe
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are creating a new thread, but you are not really doing anything with it. When you run your program, the main() method runs on one thread. If you want to start another thread and execute some code on that thread, you have to either
extend a thread,
override it's run method and put the code you want to execute on the separate thread in the run method
and then call the Thread.start to execute the code.
OR you can create an object that implements the runnable interface,
provide a run method to this object and
then create a thread with this object as an argument and then call the Thread.start to execute the code on a separate thread.
HTH
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic