Hi!
I have class 'ClientWindow' which creates the GUI for the clientside of my application.
There is a JTabbedPane in it with serveral tabs. On every tab there is a button, whenever
one of these buttons is pressed the client will send an object to the server (using socket
and streams) and waits for a reply (the return of the object). I will have to get the object's
status and write it in a JTextArea on the proper tab. This should be solved by using threads.
I want a thread for every object that is send by pressing the button. This thread should
wait untill it gets the object back from the server.
As far as I understood the thread-philosphy I have to write a class that extends Thread and
overwrites the 'run()' methode. This class will be instantiated by the 'ClientWindow' class
and the run() method will be called. But how can 'clientWindow' access the processed object
that returns from the server? run() is supposed to return 'void'....
Let's pretend this is my code:
How can I access the object, after it was processed by calling 'run()'?
Did I design the whole thing wrong??
Every thread-example I was looking at in the internet was not dealing with
data exchange between father and child. :-(
Any help is appreciated...
Cheers
frag
patrick.metz@epost.de
I have class 'ClientWindow' which creates the GUI for the clientside of my application.
There is a JTabbedPane in it with serveral tabs. On every tab there is a button, whenever
one of these buttons is pressed the client will send an object to the server (using socket
and streams) and waits for a reply (the return of the object). I will have to get the object's
status and write it in a JTextArea on the proper tab. This should be solved by using threads.
I want a thread for every object that is send by pressing the button. This thread should
wait untill it gets the object back from the server.
As far as I understood the thread-philosphy I have to write a class that extends Thread and
overwrites the 'run()' methode. This class will be instantiated by the 'ClientWindow' class
and the run() method will be called. But how can 'clientWindow' access the processed object
that returns from the server? run() is supposed to return 'void'....
Let's pretend this is my code:
Code:
public class ClientWindow extends JFrame implements ActionListener
{
public ClientWindow()
{
addWindowListener(new WindowAdapter() { public void
windowClosing(WindowEvent e) { actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "exit")); } } );
// do all the GUI stuf
}
public void actionPerformed(ActionEvent e)
{
if("execute".equals(e.getActionCommand()))
{
ScriptObj so = new ScriptObj();
ScriptThread st = new ScriptThread(so);
st.run();
}
.
.
.
}
How can I access the object, after it was processed by calling 'run()'?
Did I design the whole thing wrong??
Every thread-example I was looking at in the internet was not dealing with
data exchange between father and child. :-(
Any help is appreciated...
Cheers
frag
patrick.metz@epost.de