IOThread and Applet thread communication
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   dilek_kayhan
Posted On:   Friday, February 22, 2002 06:04 AM

HI I have an applet and I need do some I/O this blocks applet thread .. this stops applet thread painting, receiving mouse events etc so what I have did that the class that does the I/O to implement the Runnable interface how ever I do not know how to do communcition between applet thread and the thread the does the I/O basically when the thread that does the IO stops reading from a URLConnection I want to call the updateGUI() how can I determine that the IO thread has stopped and so that I can update the swing components.. I have not really used threads before so I would appreciate if some one could give some basic ideas... thanks>>>    More>>


HI
I have an applet and I need do some I/O
this blocks applet thread .. this stops applet thread painting, receiving mouse events etc
so what I have did that the class that does the I/O to implement the Runnable interface

how ever I do not know how to do communcition between applet thread and the thread the does the I/O

basically when the thread that does the
IO stops reading from a URLConnection
I want to call the updateGUI()

how can I determine that the IO thread
has stopped and so that I can update the swing components..

I have not really used threads before so I would appreciate if some one could give some basic ideas...

thanks>>>




			

class MyApplet extends JApplet
{
public void init()
{
MyPanel panel = new MyPanel();
}
}


class MyPanel extends JPanel implements Runnable
{
public void run()
{
try
{
InputStream in = anotherObject.getData();

BufferedReader reader = new BufferedReader(new InputStreamReader(in));

while ((line= reader.readLine())!=null)
{
appendResult(line);
}
reader.close();
in.close();

}try
catch(){}
}//run
}//emthod

public synchronized void appendResult(String line)
{
buffer.append(line +" ");
}

public synchronized String getResultBuffer()
{

String result = buffer.toString();
buffer = new StringBuffer();
return result;

}

//**** HOW CAN I DETERMINE WHEN TO
//CALL THIS METHOD
public void updateGUI()
{
if(getResultBuffer.equals("OK"))
{
// here update some swing components
}
}

}//class

   <<Less
About | Sitemap | Contact