Skip to content

Commit

Permalink
java-practice-key-adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
rajjitlai committed Nov 22, 2024
1 parent 1a75976 commit 8b913b1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Binary file added Java/practice/KeyAdapterExample.class
Binary file not shown.
32 changes: 32 additions & 0 deletions Java/practice/KeyAdapterExample.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 8b913b1

Please sign in to comment.