There are 2 classes:

public class InterpreterMediator1 { private String intemsg; public String getInteMSG() { return intemsg; } public void setIntemsg(String intemsg) { this.intemsg = intemsg; }} 

AND

 public class InterpreterMediator2 { private NewJFrame frame; public InterpreterMediator2(NewJFrame frame) { this.frame = frame; } public void getStr() { InterpreterMediator1 im = new InterpreterMediator1(); String s = im.getInteMSG(); frame.setJTextArea1(s); }} 

The first of the Interpreter class takes some string and passes it to the second, so that it can be called in the JFrame and shoved this string into the text of the area. The problem is that the InterpreterMediator1 line comes correctly, but in InterpreterMediator2 I already get null if, for example, output what I received through System.out. The problem, apparently, is that when I try to show the string in InterpreterMediator2, it is still empty, therefore it is null, but I did not understand how to solve this problem. I tried to put Thread.sleep there, but it waits for the allotted time and shows me null, although the string should have already arrived. How can I get strings correctly in InterpreterMediator2?

The whole project is an interpreter of BASIC, to which I am trying to fasten GUI. The interpreter source code is very difficult for me, so I make stupid crutches in the form of classes of intermediaries that would pass the information displayed by the interpreter to JFrame ... If necessary, I will drop the code for everything else.

    1 answer 1

    What would you like to get if you just created an InterpreterMediator1 object? Here it will work

     public void getStr() { InterpreterMediator1 im = new InterpreterMediator1(); im.setIntemsg("test"); String s = im.getInteMSG(); frame.setJTextArea1(s); } 

    Just what is the use of it? What problem are you solving?

    • Then yes, nothing is solved. I need that line, which came to InterpreterMediator1, there to be "delayed" for some time, and then I would get it and send it to InterpreterMediator2 and to JFrame. - Kensi
    • @Kensi It remains there until you overwrite it or destroy an instance of the class InterpreterMediator1 - Anton Shchyrov
    • Those. Is it impossible to get it in another method of another class? - Kensi
    • @Kensi there are classes, there are objects. What are you talking about? - Anton Shchyrov