Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access method and variable from one thread to another thread

Status
Not open for further replies.

prosper

Programmer
Sep 4, 2001
631
HK
public class scroll extends Applet implements Runnable
{
Thread countDownCalTd;
calObj countDownCal;
public void init()
{
countDownCal = new calObj();
Thread countDownCalTd = new Thread(countDownCal);
countDownCalTd.start();
}
public void run()
{
access method or variable from the thread of countDownCalTd
...
}
}

class calObj extends Object implements Runnable
{
public Calendar cal = Calendar.getInstance();
public boolean shouldLoop = true;
public int currentSec;
public int alarm()
{
return currentSec;
}
public void run()
{
while(shouldLoop)
{
cal = Calendar.getInstance();
currentSec = cal.get(Calendar.SECOND);
}
...
}
}
Can I call the method alarm() from the applet directly or access the variable currentSec from applet.
I need the applet running two threads concurrently. Thanks for any help!
cheungchin


 
Sure why couldn't you access alarm()? It is public so there should be no problems. Also direct access is available to currentSec but that breaks data encapsulation so you should make this a private variable. Wushutwist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top