MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.awt.BorderLayout;
import java.text.ParseException;

import javax.swing.Box;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.text.MaskFormatter;

public class MainClass {
    public static void main(String args[]) {
        JFrame f = new JFrame("JFormattedTextField Sample");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Box rowOne = Box.createHorizontalBox();
        rowOne.add(new JLabel("SSN:"));
        try {
            MaskFormatter mf1 = new MaskFormatter("###-##-####");
            rowOne.add(new JFormattedTextField(mf1));
        } catch (ParseException e) {
        }
        f.add(rowOne, BorderLayout.NORTH);

        f.setSize(300, 100);
        f.setVisible(true);
    }
}