import java.io.*; import java.util.*; import javax.swing.*; public class ConcordanceClient { public static void main(String[] args) { boolean another = true; do { String fileName = JOptionPane.showInputDialog(null, "Enter the name of a text file, Click Cancel to quit"); if (fileName != null) { Concordance table = new Concordance(fileName); System.out.println("Concordance\n" + table); System.out.println("\n\n" + "File: " + table.getFileName() + " " + table.numberOfWordsInFile() + " Words on " + table.numberOfLinesInFile() + " Lines\n"+ "Concordance has " + table.getTableSize()+ " Entries for:\n" + wordList(table.getWords()) ); processQueries(table); } else another = false; } while (another); } private static String wordList(String[] words) { String list = ""; int width = 0; for (String word : words) { list += word + " "; width += word.length() + 2; if (width >= 72) { list = list.trim() + "\n"; width = 0; } } return list.trim(); } private static void processQueries(Concordance table) { boolean another = true; do { String word = JOptionPane.showInputDialog(null, "Enter a word for look-up, Click Cancel to quit", "CONCORDANCE " + table.getFileName(), JOptionPane.PLAIN_MESSAGE); if (word == null) another = false; else { int count = table.frequency(word); String message; if (count == 0) message = "No entry for >" + word + "<"; else message = word + " (" + count + " times) on lines " + Arrays.toString(table.lineNumbers(word)); JOptionPane.showMessageDialog(null, message, "CONCORDANCE " + table.getFileName(), JOptionPane.INFORMATION_MESSAGE); } } while (another); } }