aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes create a text analysis Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "create a text analysis" Watch "create a text analysis" New topic
Author

create a text analysis

Melissa Lyn
Greenhorn

Joined: Apr 26, 2009
Posts: 3
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
Marshal

Joined: Mar 22, 2005
Posts: 42639
    
  65
Welcome to JavaRanch.

What do you have so far, and where are you stuck making progress?


Ping & DNS - my free Android networking tools app
Melissa Lyn
Greenhorn

Joined: Apr 26, 2009
Posts: 3
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Dec 13, 2008
Posts: 112
For processing words.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

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[].


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Melissa Lyn
Greenhorn

Joined: Apr 26, 2009
Posts: 3
Basically I have to do a program something like this:


[Download Text Analysis.bmp] Download

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: create a text analysis