I'm trying to create a Java text analysis application. This application contains a TextArea where user loads a text file into it as this application should contain a load button and process button. When the user clicks on the load button, the application should be able to load a text file and display the content in the TextArea. This can be done by using FileChooser component. When the user click on the process button, the application should count the number of lines in the TextArea, the number of words in the TextArea, and the number of characters in the TextArea. This information should be displayed on the three labels in the application. Please help me!!
your program has to do 3 things
1) input some data
2) process that data
3) display the processed results
don't worry about (1) or (3), until you can get the results correct (2)
i.e hard-code a string, then get this part done via System.out.println()'s
"When the user click on the process button, the application should count the number of lines in the TextArea,
the number of words in the TextArea, and the number of characters in the TextArea."
you could even use your above sentence as the hard-code
now, when you get that part workng OK, it is a simple matter of re-directing:
1) the input via a FileDialog
2) the output to labels
I'd go for a StringReader / BufferedReader combination and String.split instead. That way, you can replace the StringReader with a FileReader when you want to replace the test string with contents from an actual file. Splitting should be done at any whitespace, comma, dot but perhaps also other non-character data. And the thing with String.split is, you can give it a regular expression. For example:
Another advantage is that you can then easily count words - just check the length of the returned String.