I have a method that counts the number of words in a JTextArea. It works pretty good, except for the fact it counts characters that's not letters as words(such as "!@#$" would be a word)...
Here is the code that I have got so far(no erros, compiles and runs fine, just needs to be more specific in what it searches for)
public void processWordCount()
{
String data = textArea2.getText();
Scanner s = new Scanner(data);
Pattern p = Pattern.compile(" ");
String words = null;
int count = 0;
while (s.hasNext())
{
words = s.next();
count += 1;
}
JOptionPane.showMessageDialog(null, "Word Count: " + count);
}