Skip to content
Advertisement

Using data of one class in another class (Java/FileMenuHandler)

I have two different FileMenuHandler’s for a GUI, I need a way to use the data stored in the TreeMap from FileMenuHadler in EditMenuHandler. EditMenuHandler is supposed to ask the user to enter a word and search in the TreeMap if the word exists.

I tried to create an instance of FMH in EMH but the Tree was always empty, how can I save the values of the tree once the file is opened and then use it for EditMenuHandler?

JavaScript
JavaScript

Advertisement

Answer

there are many ways to do this,

  1. you can declare a static filed (not recommended)
  2. use RXJava or LiveData
  3. use EventBus
  4. use interface as a listener ….
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement