forked from patniemeyer/learningjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextEntryBox.java
More file actions
32 lines (26 loc) · 885 Bytes
/
Copy pathTextEntryBox.java
File metadata and controls
32 lines (26 loc) · 885 Bytes
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
//file: TextEntryBox.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextEntryBox {
public static void main(String[] args) {
JFrame frame = new JFrame("Text Entry Box");
final JTextArea area = new JTextArea();
area.setFont(new Font("Serif", Font.BOLD, 18));
area.setText("Howdy!\n");
final JTextField field = new JTextField();
Container content = frame.getContentPane();
content.add(new JScrollPane(area), BorderLayout.CENTER);
content.add(field, BorderLayout.SOUTH);
field.requestFocus();
field.addActionListener(new ActionListener( ) {
public void actionPerformed(ActionEvent ae) {
area.append(field.getText( ) + '\n');
field.setText("");
}
});
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setSize(200, 300);
frame.setVisible(true);
}
}