A TextField that uses key events to correct the spelling of the names of computer languages entered into it #Programming Code Examples #Java/J2EE/J2ME #Mouse and Keyboard Events

import java.awt.*;
import java.awt.event.*;

/** A spelling-correcting TextField for entering
 *  a language name.
 *  

******************* public class LanguageField extends TextField { private String[] substrings = { "", "J", "Ja", "Jav", "Java" }; public LanguageField() { addKeyListener(new SpellingCorrector()); addActionListener(new WordCompleter()); addFocusListener(new SubliminalAdvertiser()); } // Put caret at end of field. private void setCaret() { setCaretPosition(5); } // Listener to monitor/correct spelling as user types. private class SpellingCorrector extends KeyAdapter { public void keyTyped(KeyEvent event) { setLanguage(); setCaret(); } // Enter partial name of good programming language that // most closely matches what they've typed so far. private void setLanguage() { int length = getText().length(); if (length < = 4) { setText(substrings[length]); } else { setText("Java"); } setCaret(); } } // Listener to replace current partial name with // most closely-matching name of good language. private class WordCompleter implements ActionListener { // When they hit RETURN, fill in the right answer. public void actionPerformed(ActionEvent event) { setText("Java"); setCaret(); } } // Listener to give the user a hint. private class SubliminalAdvertiser extends FocusAdapter { public void focusGained(FocusEvent event) { String text = getText(); for(int i=0; i<10; i++) { setText("Hint: Java"); setText(text); } } } }

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10367
Categories:Programming Code Examples, Java/J2EE/J2ME, Mouse and Keyboard Events
Tags:Java/J2EE/J2MEMouse and Keyboard Events
Post Data:2017-01-02 16:04:35

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Leave a Reply