Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

create a text analysis

 
Melissa Lyn
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

What do you have so far, and where are you stuck making progress?
 
Melissa Lyn
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So far I have like this:



haven't really completed much stuff since I don't really know how to continue from here. And I'm not sure whether my codes here are correct too.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Mikko Kohtamäki
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For processing words.
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mikko Kohtamäki wrote:For processing words.

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[].
 
Melissa Lyn
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically I have to do a program something like this:
Filename: Text Analysis.bmp
Description: Text Analysis
File size: 876 Kbytes
[Download Text Analysis.bmp] Download Attachment
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic