A
A
Anatoly Evladov2014-10-14 11:50:07
Java
Anatoly Evladov, 2014-10-14 11:50:07

Java, how to properly work with windows?

Actually the question is, what can be read about this? What can be seen from the sources on the git for example?
The problem is this, in the application you can have quite a lot of different windows, naturally they must somehow interact with each other. In general terms, I understand that there is a controller that works with a window, but I believe that it should not be able to directly affect another window. But at the same time, what to do if, after performing certain actions in the first window, you need to call the second - I don’t really understand.
Can anyone suggest which way to dig? If it will be with a code example, it will be generally wonderful.
PS I realized that you can "subscribe" to certain events, but how it works in practice is not very clear.
I am using Java FX. I haven't worked much with the GUI before. So I ask for help, for the third day I have been racking my brains on how to organize the interaction between windows.
If something described is not very clear - write, I will correct it.
PPS Still interested in this question, the license allows you to use the product for commercial purposes? And do you have to pay interest?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Luke Vost, 2014-11-22
@Visteras

You can declare a whole class as static or without static, but it has some variables, methods, as static and have access to them from all parts of the program at any time. Those. and thus build interaction between different window controllers. In this class, you can store only the necessary references to objects and use them at the right time, respectively, and the limited interaction you need will be.
I constantly use this method to communicate between windows, it is a completely working solution, without wasting resources and time.
Example: for example, in the initialize block you create our common class, through the constructor or through the method you set all the necessary references to the necessary objects, for example, some fields or the necessary variables. Then in another window controller anywhere you can already access the already shared fields, variables and whatever you see fit.
As I understand you are a beginner, here is a simple example:

public static class outStaticClass{
   public Button commonButton; //Общая кнопка.
 }

public class controllerWindow1 implements Initializable{
   private Button ourButtonForCommonClass;
   ...
  @Override
    public void initialize(URL url, ResourceBundle rb) {
     ourButtonForCommonClass = new Button("First button");
     outStaticClass oSC = new outStaticClass();
     outStaticClass.commonButton = ourButtonForCommonClass; // Сохранили ссылку на объект
    }
 }

public class controllerWindow2 implements Initializable{
  ... 
  //В любом месте  outStaticClass oSC = new outStaticClass();
  //и у нас есть доступ к объекту из первого окна controllerWindow1
  //можем изменить его текст или сделать disabled
  //лучше сделать не прямое взаимодействие через наш общий класс.
 }

As for the license, I have no idea, to be honest, ask a separate question, it’s also interesting by the way.
You can also, through static, bind many fields, values, and so on using bind.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question