88 Week10
88 Week10
88 Week10
WEEK-10(Programs)
PROGRAM :
import java.awt.*; import
java.applet.Applet; import
java.awt.event.*;
g.drawString(msg,x,y); } }
2) PROBLEM STATEMENT: Write a java program to implement
KeyEvents PROGRAM
:
import java.awt.*; import java.awt.event.*; public class
Label I;
TextArea area;
Frame f;
KeyAdapterExample() { f=new
Label();
I.setBounds(20,50,200,20);
area=new TextArea();
area.setBounds(20,80,300,300);
area.addKeyListener(this);
f.add(I);
f.add(area);
f.setSize(400,400);
f.setLayout(null);
keyReleased(KeyEvent e) {
String text=area.getText();
String words[]=text.split("\\s");
I.setText("words:"+words.length+ "characters:"+text.length()); }
} }
java.awt.event.*;
Label l;
TextArea area;
setSize(400, 400); l
= new Label();
keyPressed(KeyEvent e)
keyReleased(KeyEvent e) {
words[] = text.split("\\s+");
l.setText("Released - Words: " + words.length + " Characters: " + text.length()); } });