forked from patniemeyer/learningjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormattedFields.java
More file actions
40 lines (34 loc) · 1.18 KB
/
Copy pathFormattedFields.java
File metadata and controls
40 lines (34 loc) · 1.18 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
import java.text.*;
import javax.swing.*;
import javax.swing.text.*;
import java.util.Date;
public class FormattedFields
{
public static void main( String[] args ) throws Exception {
Box form = Box.createVerticalBox();
form.add( new JLabel("Name:") );
form.add( new JTextField("Joe User") );
form.add( new JLabel("Birthday:") );
JFormattedTextField birthdayField =
new JFormattedTextField(new SimpleDateFormat("MM/dd/yy"));
birthdayField.setValue( new Date() );
form.add( birthdayField );
form.add( new JLabel("Age:") );
form.add(new JFormattedTextField(new Integer(32)));
form.add( new JLabel("Hairs on Body:") );
JFormattedTextField hairsField
= new JFormattedTextField( new DecimalFormat("###,###") );
hairsField.setValue(new Integer(100000));
form.add( hairsField );
form.add( new JLabel("Phone Number:") );
JFormattedTextField phoneField =
new JFormattedTextField( new MaskFormatter("(###)###-####") );
phoneField.setValue("(314)555-1212");
form.add( phoneField );
JFrame frame = new JFrame("User Information");
frame.getContentPane().add(form);
frame.pack();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setVisible(true);
}
}