-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakeTextBox.java
More file actions
44 lines (32 loc) · 1.3 KB
/
MakeTextBox.java
File metadata and controls
44 lines (32 loc) · 1.3 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
import javax.swing.*;
import java.awt.*;
//I should put in labels too.
class MakeTextBox{
public static void main(String args[]){
JFrame frame = new JFrame("I am a title");
frame.setSize(200, 200);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
//Also, if I don't have a layout of the frame, then the components in the pane
//will be arranged undesirably.
frame.setLayout(new FlowLayout());
//If the line below is commented out, then the container is presented
//irregularaly.
//frame.setVisible(true);
//According to the articles I've read, the JPanel is a nice
//way to wrap all the components together.
//JPanel pane = new JPanel();
//JTextField does not have a default operationg that makes everything look nice.
//I need to specify the field length through the constructor.
JTextField field = new JTextField(10);
JLabel label = new JLabel("I am so cool");
JPanel pane = new JPanel();
pane.add(field);
pane.add(label);
//I can either add the components to the frame,
//frame.add(label);
//frame.add(field);
//or I can add the components inside the frame.
frame.add(pane);
frame.setVisible(true);
}
}