import java.applet.Applet;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextArea;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JOptionPane;
public class NewApplet4 extends
Applet implements KeyListener {
Frame f=new Frame();
Label l,l1;
TextArea area;
public void init() {
l = new Label();
l1= new Label();
l.setBounds (20, 50, 200, 20);
l1.setBounds(225, 50, 200, 20);
area = new TextArea();
area.setBounds (20, 80, 300,
300);
area.addKeyListener(this);
f.add(l);
f.add(l1);
f.add(area);
f.setSize (400, 400);
f.setLayout (null);
f.setVisible (true);
}
@Override
public void keyTyped(KeyEvent e) {
l.setText ("Key Typed");
}
@Override
public void keyPressed(KeyEvent e) {
l.setText ("Key Pressed");
}
@Override
public void keyReleased(KeyEvent e) {
l.setText ("Key Released");
String text = area.getText();
String words[] = text.split
("\\s");
l1.setText ("Words: " +
words.length + " Characters:" + text.length());
if (e.getKeyCode() == KeyEvent.VK_ENTER)
JOptionPane.showMessageDialog(f, "You have stopped typing the text",
"STOP TYPING", JOptionPane.INFORMATION_MESSAGE);
}
}
OUTPUT:
No comments:
Post a Comment