0

I'm doing a small project which counts word from .txt files or webpages. while doing it, I got a problem.

There are GUI windows A, B

A performs targeting .txt files in local or webpages. B performs printing text from the target and giving options of whether or not a user starts counting words from the text

so, when a user clicks the button 'word count' in B, the user can see word list and word count each word in A. I'd like to get Map<String word, Integer frequency> from B as soon as the user clicks the button 'word count' and to show words and frequency each word at JList in A.

The problem is that I cannot come up with how to handle events from B in A. one of the ways I considered is creating a class with A,B in it as member... but I'm not able to proceed..

p.s. I'm Korean novice programmer. so, please understand my poor English skill..

fabian
  • 80,457
  • 12
  • 86
  • 114

1 Answers1

0

If A and B are two separate GUI applications, that means you have two separate processes running. What you need here is "inter process" communication.

From application A, you keep writing the data on the file system . From application B , you just read the data from the file system and use as you wish.

EDIT -

looking at comments , i can suggest you is that you need to share a model object in multiple threads.

    class ModelObject{
    //This should hold your data in final fields. Make it immutable.
}

// You can make it singleton.
        Class SharedService{
Private volatile ModelObject model ;
   Public void write(ModelObject model);
  Public ModelObject read();
}

Application A writes data using SharedService, encapsulate data in to class ModelObject. Application B reads data using SharedService.get interface.

Gunwant
  • 949
  • 1
  • 14
  • 29
  • There are better ways to communicate, than writing files, see http://stackoverflow.com/a/10942526/2991525 . Furthermore the OP clarified in a comment, that it's really about communicating between 2 different windows of the same application. – fabian Aug 11 '16 at 06:17
  • you mean two main-thread running? then I would say 'no'. There is one main-thread. To be specific, JFrame A(is the same as GUI applicaion A as I said above) create JFrame B object in it. – TrailblazerChoong Aug 11 '16 at 06:28
  • In that case you need sharing an object with multiple threads. – Gunwant Aug 11 '16 at 08:40