i having thread class ,each time when i am calling it creates new object and run new thread, i want to access specified thread variable from another class. is it possible??? help me....

Yes, its possible. But without seeing your code and some more detail on exactly what you need to do, it's not possible to give an exact answer.

public class one implements Runnable


    public one() {
        Thread t=new Thread();
       t.start();
    }
public static void main(String args[])
{
   new one();
}
    @Override
    public void run() {
        new newguiclass();

    }

}

class threadd extends newguiclass implements Runnable 
{
    public void run()
    {
        new server();
    }
}

 class server extends newguiclass implements Runnable
{

    public server() {

    // **
## have to use desk here ##
**
    }


}
class newguiclass extends one implements Runnable
{
JDesktopPane desk;
    public newguiclass() {
        Thread g = new Thread(this);
        g.start();
    }
     public void run() {
    desk=new JDesktopPane();
     }

}

have to access desktop pane in server class from newguiclass

since it extends the class

public server(){
  desk. ...
}

should do the trick. make sure it's instantiated first, though, meaning your run method must run before your server constructor (which is not possible) or you must instantiate your desk variable in your server constructor

  1. Pass the instance of the desktop pane as a aparameter to the constructors of eveything that needs it
    or
  2. Write a public static method in the server class that will return the current instance, so anyone can call that method when they need the desktop pane instance

If there is only ever going to be one instance of desktop pane then solution (2) is simpler.

  • desk=new JDesktopPane(); should be created on Initial Thread,

  • quite sure that in Java7 nothing happened on the screen, in Java6 are chances very volatille

(I took a quick look at the various classes and threads and decided not to worry about them. Presumably this is an arbitrary complex Thread test kind of exercise, because it doesn't relate to anything practical I can think of. I got as far as the main that instantates a "one" whose constructor starts an empty thread that will do nothing, "threadd" and "server" classes that are never used, and a gui class that's carefully instatiated on a new thread that is NOT the swing EDT)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.