Skip to content
Advertisement

How can I access the same text area variable?

The code below works as such:

  • User clicks the run button
  • Program reads the file from designated location
  • Program removes content from <script> </script>, including tags themselves
  • Program returns edited text into JTextArea called textArea

I’ve tried making it a global variable since it’s in two different classes. The run down is that once the user clicks the “run button”, the text area initialised in the GUI class will update.

JavaScript

Advertisement

Answer

3 options:

  • Make your listener class an inner class of GUI, then it will have access to all fields of it’s outer class (no need for static in that case)
  • Keep the 2 classes completely separate, and pass a reference to the text field to the listener (e.g. via constructor parameter).
  • access the static field via GUI.textArea
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement