import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class SpellChecker extends JFrame { JTextArea textArea; JTextField stringField; JScrollPane scrollPane; String[] words; public SpellChecker () { // Set some parameters of the frame (window) that's brought up. this.setSize (600, 600); this.setTitle ("Spell checker"); this.setResizable (true); // This is how stuff is put into a frame. Container cPane = this.getContentPane(); textArea = new JTextArea (); scrollPane = new JScrollPane (textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); cPane.add (scrollPane, BorderLayout.CENTER); // Make the controls. JPanel panel = new JPanel (); JLabel label = new JLabel ("Enter string: "); panel.add (label); stringField = new JTextField (30); panel.add (stringField); JButton button = new JButton ("Go"); button.addActionListener ( new ActionListener () { public void actionPerformed (ActionEvent a) { handleButtonClick(); } } ); panel.add (button); cPane.add (panel, BorderLayout.SOUTH); // Read in dictionary. words = WordTool.getDictionary (); this.setVisible (true); } String inputStr; // When the user clicks the button, this method gets called. // It's where we need to respond. void handleButtonClick () { // Extract the string from the textfield where the user typed the strings. inputStr = stringField.getText (); String[] matchedWords = findClosestWords (inputStr, words); String outputStr = ""; if (matchedWords == null) { outputStr = "No matches found"; } else { for (int i=0; i