class one { Server_Form okno = new Server_Form(); okno.setVisible(true); } class two { // Как организовать доступ обьекта "okno" из класса one в этом классе? // Чтобы я мог сделать следующее: okno.command_serv(); } 
  • Nothing is clear. Why can't you just refer to okno in two? - cy6erGn0m
  • And how to pass this link? I'm new, sorry. - zorgi pm

2 answers 2

 class One { private Two two; public void test() { ServerForm okno = new ServerForm(two); okno.setVisible(true); okno.commandServ(); } } class Two { public void doSometing(){ } } class ServerForm ...... { private final Two two; public ServerForm(Two two) { this.two = two; } // .. setVisible, etc public void commandServ() { two.doSomething(); } } 
     class one { private JFrame wnd = null ; public void someMethod() { if (null == wnd) { wnd = new JFrame(); } wnd.setVisible(true); } public JFrame getWnd () { return wnd ; } public void setWnd ( JFrame wnd ) { this.wnd = wnd ; } } class two { public void someMethod (one ref) { ref.getWnd ().setVisible ( false ); } } 

    free tips:
    1) never use translit in program code, for this you will go to hell for coders!
    2) never call classes with a small letter, for that you will go to hell for coders!