Karl Blessing
Programmer
I have the following example<br>
<br>
import java.lang.Thread;<br>
<br>
public class TCon<br>
{<br>
int MyNum;<br>
public static void main (String[] args)<br>
{<br>
Thread F = new RThread("T1", 250);<br>
Thread S = new RThread("T2", 750);<br>
<br>
F.start();<br>
S.start();<br>
<br>
try<br>
{ System.in.read(); }<br>
catch (java.io.IOException ioe)<br>
{ }<br>
F.stop();<br>
S.stop();<br>
}<br>
public synchronized void setnumber(int newnum)<br>
{<br>
MyNum = newnum;<br>
}<br>
public synchronized int getnumber()<br>
{<br>
return MyNum;<br>
}<br>
}<br>
class RThread extends Thread <br>
{<br>
private String message;<br>
private int duration;<br>
<br>
public RThread(String m, int d)<br>
{<br>
message = m;<br>
duration = d;<br>
}<br>
public void run()<br>
{ <br>
try<br>
{<br>
while(true)<br>
{<br>
System.out.println(message);<br>
try<br>
{<br>
sleep(duration);<br>
}<br>
catch (InterruptedException ie)<br>
{<br>
System.out.println("Interrupted"<br>
return;<br>
}<br>
}<br>
}<br>
finally<br>
{<br>
System.out.println(message+" shut down"<br>
}<br>
}<br>
}<br>
<br>
(this is just an example i'm learning with)<br>
now what I want to be able to do, is have the thread be able<br>
to call the setnumber, and getnumber located in the main/parent thread. but i do not know how to get ahold of it.<br>
(in C++ i would not normally just make a class pointer of the parent type, and assign its location, but pointers dont exist in java, and so on) <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(least i didnt start with COBOL)
<br>
import java.lang.Thread;<br>
<br>
public class TCon<br>
{<br>
int MyNum;<br>
public static void main (String[] args)<br>
{<br>
Thread F = new RThread("T1", 250);<br>
Thread S = new RThread("T2", 750);<br>
<br>
F.start();<br>
S.start();<br>
<br>
try<br>
{ System.in.read(); }<br>
catch (java.io.IOException ioe)<br>
{ }<br>
F.stop();<br>
S.stop();<br>
}<br>
public synchronized void setnumber(int newnum)<br>
{<br>
MyNum = newnum;<br>
}<br>
public synchronized int getnumber()<br>
{<br>
return MyNum;<br>
}<br>
}<br>
class RThread extends Thread <br>
{<br>
private String message;<br>
private int duration;<br>
<br>
public RThread(String m, int d)<br>
{<br>
message = m;<br>
duration = d;<br>
}<br>
public void run()<br>
{ <br>
try<br>
{<br>
while(true)<br>
{<br>
System.out.println(message);<br>
try<br>
{<br>
sleep(duration);<br>
}<br>
catch (InterruptedException ie)<br>
{<br>
System.out.println("Interrupted"<br>
return;<br>
}<br>
}<br>
}<br>
finally<br>
{<br>
System.out.println(message+" shut down"<br>
}<br>
}<br>
}<br>
<br>
(this is just an example i'm learning with)<br>
now what I want to be able to do, is have the thread be able<br>
to call the setnumber, and getnumber located in the main/parent thread. but i do not know how to get ahold of it.<br>
(in C++ i would not normally just make a class pointer of the parent type, and assign its location, but pointers dont exist in java, and so on) <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(least i didnt start with COBOL)