"once I click my "Analyze to text" button,"
Could be maybe the actionCommand is not "Text"
and you should be checking if "Analyze to text"
if ("Text".equals(command)) {
→if ("Analyze to Text".equals(command)) {
// or whatever the text/actionCommand of your button is
Another seemingly obvious problem, is you have declared JFileChooser chooser
but you're trying to access filechooser
UPDATE
Use this code. Change your button text back. If it doesn't work, then you changed something else in your code, and I can't help, because this works fine for me.
if ("Analyze Text File".equals(command)) {
JFileChooser chooser = new JFileChooser();
int result = chooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
try {
File file = chooser.getSelectedFile();
BufferedReader reader = new BufferedReader(new FileReader(file));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
String text = sb.toString();
Map<Integer, Integer> counts = getCounts(text);
int width = counts.size() * BAR_WIDTH;
int max = maxCount(counts);
int height = max * INCREMENT + 100;
int horizon = height - 25;
HistogramPanel panel = new HistogramPanel(width, counts, height, horizon);
JOptionPane.showMessageDialog(null, panel);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}