I have this project that requires me to count the occurrences of each character inputted in the JTextArea and output each character with how many times it occurred into another text box by clicking a button. My code only works for the last character of the string, it displays and counts that specific character but not the rest of the characters in the string. I need my code to count all of the characters and output it. Can someone help.
Here's my code:
btnStat.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String text = textbox1.getText();
int counted[] = new int[MAX_CHAR];
int sizes = text.length();
int find = 0;
char[] cat = new char[text.length()];
for (int i = 0; i < sizes; i++) {
cat[i] = text.charAt(i);
for (int j = 0; j <= i; j++) {
if (text.charAt(i) == cat[j]) {
find++;
}
textbox6.setText("Character Frequency: \n '" + text.charAt(j) + "' - " + counted[text.charAt(j)] + " ,");
}
}
}
}