keypress thingy in Java

A small keypress, read in array using swing thingy.

package keypress;
 
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
 
import javax.swing.JFrame;
import javax.swing.JTextField;
 
public class Key extends KeyAdapter{
 
	KeyListener key;
	String[] names = {"woord", "letter", "huis"};
	JTextField textField = new JTextField();
 
	public Key() {
		JFrame frame = new JFrame();
		frame.getContentPane().add(textField);
		frame.setVisible(true);
		frame.setSize(400,400);
		textField.addKeyListener(this);	
	}
 
	public void keyTyped(KeyEvent k) {
		char x = k.getKeyChar();
 
		for (String i : names) {
			if (i.charAt(0) == x) {
				textField.setText(i);
				k.setKeyChar(' ');
			}
		}
	}
 
	public static void main(String[] args) {
		Key k = new Key();
 
	}

Leave a Reply