diff --git a/Java/practice/KeyAdapterExample.class b/Java/practice/KeyAdapterExample.class new file mode 100644 index 0000000..1a8d3a3 Binary files /dev/null and b/Java/practice/KeyAdapterExample.class differ diff --git a/Java/practice/KeyAdapterExample.java b/Java/practice/KeyAdapterExample.java new file mode 100644 index 0000000..27e5fe9 --- /dev/null +++ b/Java/practice/KeyAdapterExample.java @@ -0,0 +1,32 @@ +import java.awt.*; +import java.awt.event.*; + +public class KeyAdapterExample extends KeyAdapter { + Label l; + TextArea area; + Frame f; + + KeyAdapterExample() { + f = new Frame("Key Adapter"); + l = new Label(); + l.setBounds(20, 50, 200, 20); + area = new TextArea(); + area.setBounds(20, 80, 300, 300); + area.addKeyListener(this); + f.add(l); + f.add(area); + f.setSize(400, 400); + f.setLayout(null); + f.setVisible(true); + } + + public void keyReleased(KeyEvent e) { + String text = area.getText(); + String words[] = text.split("\\s"); + l.setText("Words: " + words.length + " Characters:" + text.length()); + } + + public static void main(String[] args) { + new KeyAdapterExample(); + } +} \ No newline at end of file