I'm trying to build a small GUI application where users can input text (in a JTextArea) and by pressing a button, you get a summary of how many times each word in the text has occurred.
So here come the questions.
First, the GUI itself. The way I envisage it to be built is with a JLabel on the top, explaining briefly what the application is about, JTextArea holding the text to process, another JTextArea to hold the results, a JPanel with two buttons, a "process button" to kick things off and let the application count the words in the text and a "clear" button which clears both JTextAreas.
Something like this:
-JFrame (default BorderLayout) -JPanel griBagLayout(positioned North) -JLabel -JTextArea for sample text -JPanel griBagLayout (positioned Center) -JButton to process -JButton to clear first JTextArea -JTextArea for result (positioned South)
As far as the functionality is concerned instead, I was thinking to have a named handler class with a constructor taking a false or true parameter to determine which button is being pressed and act as a consequence of that: if the parameter is true, then it's the clear button, therefore clear everything, if true is the process button. So, something like this:
... clearButton.addActionListener(new ButtonHandler(true)); processButton.addActionListener(new ButtonHandler(false)); ...
Is that a good way to distinguish the buttons?
Finally, the functionality to process the text. I want to be able to process a lot of text, not just a few sentences. After reading here and there I was thinking to perhaps save all that text in the JTextArea in a String variable, use the the String's split method (split at a blank space) so that everything goes into an array and thn implement some kind of counter - I haven't thought exactly what kind of counter as yet though - do you guys reckon that would work?