Go to Post Why is the battery labeled "battery"? - Vermeulen [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-04-2010, 01:04
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
Threads and classes

Hello all.

How come when I make a class into a thread, I cannot use the class as an object anymore?

I'm calling it as

public Thread foo = new FooThread();

where FooThread has function bar() which printfs "FOOBAR".

Using threads, how can I call foo.bar() inside my main loop?
Reply With Quote
  #2   Spotlight this post!  
Unread 01-04-2010, 07:55
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Re: Threads and classes

Consult this tutorial for how to use threads in Java:

http://java.sun.com/docs/books/tutor...l/concurrency/
__________________
I don't need a signature.
Reply With Quote
  #3   Spotlight this post!  
Unread 03-04-2010, 20:07
spartango spartango is offline
Registered User
FRC #0192 (GRT)
Team Role: Alumni
 
Join Date: Nov 2009
Rookie Year: 2008
Location: Palo Alto, CA
Posts: 43
spartango is an unknown quantity at this point
Re: Threads and classes

If FooThread extends thread, then you can still call foo.bar(), but you have to cast the pointer to the FooThread instance to be not a Thread but a FooThread.

So

Thread t = new FooThread();
//you can now start thread or do whatever
//ie
t.start();

//you cannot, however do this:
t.bar();
//Because not ever thread has bar() method. only FooThreads do.
//but this will work:
((FooThread) t).bar();

//Alternatively, you can create your pointer as a FooThread type as opposed to simply a thread
FooThread t = new FooThread();
//this way you can
t.start();
t.bar();
Reply With Quote
  #4   Spotlight this post!  
Unread 03-04-2010, 23:31
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
Re: Threads and classes

Oh, wow, I can't believe I missed that, XD

thanks
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
do you guys attend classes regularly during the time between kickoff and shipment? Nimmy General Forum 56 26-02-2006 21:38
Descriptions and such in image threads? Billfred CD Forum Support 5 06-06-2005 10:01
Religion threads and the CD rules Billfred CD Forum Support 22 30-04-2005 14:49
FREE web design, php, and 3ds max classes Jeremy_Mc General Forum 0 31-01-2003 15:42


All times are GMT -5. The time now is 18:42.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi