forked from vanithaak/first-year-java-practicals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypedCharWithSwing.java
46 lines (40 loc) · 942 Bytes
/
TypedCharWithSwing.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TypedCharWithSwing
{
JLabel l;
String msg=" Typed character is :<";
public TypedCharWithSwing ()
{
JFrame f=new JFrame(" ");
l=new JLabel();
f.setSize(300,300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new FlowLayout());
f.setVisible(true);
f.add(l);
f.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent ke)
{
msg+=ke.getKeyChar();
l.setText(msg);
f.repaint();
}
});
}
public void main(Graphics g)
{
g.drawString(msg, 400, 400);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable(){
public void run()
{
new TypedCharWithSwing ();
}
});
}
}