-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMyFrame.java
More file actions
98 lines (79 loc) · 2.33 KB
/
Copy pathMyFrame.java
File metadata and controls
98 lines (79 loc) · 2.33 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyFrame extends JFrame implements ActionListener,KeyListener{
TextField input;
List l1;
String data;
Button b;
// Label img;
MyFrame(String title){
super(title);
data="";
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
dispose();
data="****";
}
});
setSize(400,550);
l1=new List();
l1.setBounds(0,0, 400,450);
add(l1);
input=new TextField("");
input.setBounds(0,465,350,25);
add(input);
b=new Button("Send ");
b.setBounds(350,465,50,25);
b.addActionListener(this);
add(b);
input.addKeyListener(this);
// img=new Label("Typing...") ;
// img.setBounds(100,460,200,60);
// add(img);
// img.setVisible(false);
setResizable(false);
setLayout(null);
setVisible(true);
}
public void keyPressed(KeyEvent e) {
try{
if((int) e.getKeyChar()==10){
data=input.getText();
// data="YOU: "+data;
l1.add("YOU: "+data,0);
input.setText("");
}
}catch(Exception ex){System.out.println(ex);}
// System.out.println((int) e.getKeyChar());
}
public String getString(){
// System.out.println(data);
// input.setVisible(true);
String ans=this.data;
this.data="";
return ans;
}
public void addString(String str){
l1.add("PERSON: "+str,0);
// input.setVisible(false);
}
// public void setFlag(boolean f){
// input.setVisible(f);
// b.setVisible(f);
// f=!f;
// img.setVisible(f);
// }
public void keyReleased(KeyEvent e) {
// l.setText("Key Released");
}
public void keyTyped(KeyEvent e) {
// l.setText("Key Typed");
}
public void actionPerformed(ActionEvent e) {
try{
l1.add(input.getText());
input.setText("");
}catch(Exception ex){System.out.println(ex);}
}
}