11.7. A Spelling-Correcting Textfield

Listing 11.9 shows a spelling-correcting textfield that lets the user enter the name of a good programming language. The textfield monitors three types of events: key events (when a printable character is typed while the textfield has the keyboard focus), focus events (when the textfield obtains the keyboard focus), and action events (when ENTER is pressed while the textfield has the focus). When it detects a printable character (through the keyTyped method of the KeyAdapter class), it compares the string entered so far to a dictionary of good programming languages and replaces the string entered with the most closely matching substring from its dictionary. When it detects ENTER (through the actionPerformed ...

Get Core Web Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.