-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyWindow.java
More file actions
66 lines (54 loc) · 1.85 KB
/
MyWindow.java
File metadata and controls
66 lines (54 loc) · 1.85 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
package GeekBrains;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MyWindow extends JFrame {
public MyWindow() {
setTitle("Window");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setBounds(300, 300, 600, 400);
JButton jbs = new JButton();
JTextArea jta = new JTextArea();
JScrollPane jsp = new JScrollPane(jta);
JTextField field = new JTextField();
setLayout(null);
// textarea
jta = new JTextArea("Enter your message...");
add(jta);
jta.setBounds(100, 50, 400, 200);
//jta.setLayout(new BorderLayout()); не понял как включить скролл если так, то нельзя ничего ввести
//jta.add(jsp);
// ввод
add(field);
field.setBounds(100,260,300,50);
JTextArea finalJta = jta;
field.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Your message: " + field.getText());
finalJta.append("\n"+field.getText());
}
});
// send
jbs = new JButton("Send");
add(jbs);
jbs.setBounds(410, 260, 90, 50);
jbs.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Your message: " + field.getText());
finalJta.append("\n"+field.getText());
}
});
JButton button = new JButton("Button");
add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
finalJta.append("\n"+field.getText());
}
});
setVisible(true); // видимость формы на экране. Лучше вызывать последней
}
}// class