title: Using data of one class in another class (Java/FileMenuHandler)
body: <p>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.</p>
  <p>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?</p>
  <pre><code>import java.util.*;
  import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  import java.io.*;
  
  public class FileMenuHandler implements ActionListener{
      JFrame jframe;//creating a local JFrame 
      public FileMenuHandler (JFrame jf){//passing WordGUI Jframe
         jframe = jf;
      }
  
      private Container myContentPane;
      private TextArea myTextArea1;
      private TextArea myTextArea2;
      protected ArrayList&lt;Word&gt; uwl = new ArrayList&lt;Word&gt;(); 
      protected TreeMap&lt;Word, String&gt; tree; 
  
      private void readSource(File choosenFile){
          String choosenFileName = choosenFile.getName();
          TextFileInput inFile = new TextFileInput(choosenFileName);
          
          myContentPane = jframe.getContentPane();
          myTextArea1 = new TextArea();
          myTextArea2 = new TextArea();
  
          myTextArea1.setForeground(Color.blue);
          myTextArea2.setForeground(Color.blue);
  
          Font font = new Font(&quot;Times&quot;, Font.BOLD, 20);
          myTextArea1.setFont(font);
          myTextArea2.setFont(font);
  
          myTextArea1.setBackground(Color.yellow);
          myTextArea2.setBackground(Color.yellow);
  
  
  
  
          String paragraph = &quot;&quot;;
          String line = inFile.readLine();
          while(line != null){
              paragraph += line + &quot; &quot;;
              line = inFile.readLine();
          }
  
          StringTokenizer st = new StringTokenizer(paragraph);
          tree = new TreeMap&lt;Word,String&gt;();
          while(st.hasMoreTokens()){
              
              String word = st.nextToken();
              Word w = new Word(word);
              uwl.add(w);
              tree.put(w,w.data);
  
          }
  
          for(int i = 0; i &lt; uwl.size(); i++){
              myTextArea1.append(uwl.get(i).data + &quot;\n&quot;);
          
              }
              
              myTextArea2.append(tree + &quot;\n&quot;);
  
          
          myContentPane.add(myTextArea1);
          myContentPane.add(myTextArea2);
  
          jframe.setVisible(true);           
       }
  
  
      private void openFile(){
          int status;
          JFileChooser chooser = new JFileChooser(&quot;./&quot;);
          status = chooser.showOpenDialog(null);
          readSource(chooser.getSelectedFile());
  
      }
  //instance of edit menu handler
  
      public void actionPerformed(ActionEvent event) {
          String menuName = event.getActionCommand();
          if (menuName.equals(&quot;Open&quot;)){
              openFile();
          }
          else if (menuName.equals(&quot;Quit&quot;)){
              System.exit(0);
          }
              
       } //actionPerformed
  
  }
  //
  
  </code></pre>
  <pre><code>import java.awt.event.*;
  
  public class EditMenuHandler implements ActionListener {
      JFrame jframe;
  
      public EditMenuHandler(JFrame jf) {
          jframe = jf;
      }
  
      public void actionPerformed(ActionEvent event) {
          String menuName = event.getActionCommand();
          if (menuName.equals(&quot;Search&quot;)) {
              JOptionPane.showMessageDialog(null, &quot;Search&quot;);
          }
      }
  }
  
  </code></pre>