How to validate a JTextField in eclipse?
<p>I want to be able to validate a number of different JTextFields in my java project. One being to ensure the user enters a number into a particular field. 
Another problem I'm having is being able to validate a particular number, such as 1234 in a field when a submit button is pressed.</p>

<p>If I have to create a method in a separate class then that fine but how would I call the method into my GUI class to use for my JTextField.</p>

<p>I'm quite new to Java and find some of this hard so any help is greatly appreciated.</p>

<p>At the minute I have:</p>

<pre><code>import java.awt.BorderLayout;

public class CashDialog extends JDialog {

    private final JPanel contentPanel = new JPanel();
    private JTextField txtEmilysBistro;
    private JTextField textconfirmNumber;
    private String confirmNumber;
    private JButton btnSubmit;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        try {
            CashDialog dialog = new CashDialog();
            dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            dialog.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Create the dialog.
     */
    public CashDialog() {

        this.confirmNumber = confirmNumber;

        setBounds(100, 100, 526, 372);
        getContentPane().setLayout(new BorderLayout());
        contentPanel.setBackground(new Color(255, 0, 153));
        contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        getContentPane().add(contentPanel, BorderLayout.CENTER);
        contentPanel.setLayout(null);
        {
            txtEmilysBistro = new JTextField();
            txtEmilysBistro.setBackground(new Color(255, 0, 153));
            txtEmilysBistro.setHorizontalAlignment(SwingConstants.CENTER);
            txtEmilysBistro.setForeground(new Color(255, 255, 255));
            txtEmilysBistro.setFont(new Font("AR ESSENCE", Font.PLAIN, 50));
            txtEmilysBistro.setEditable(false);
            txtEmilysBistro.setText("Emily's Bistro");
            txtEmilysBistro.setBounds(0, 0, 504, 57);
            contentPanel.add(txtEmilysBistro);
            txtEmilysBistro.setColumns(10);
        }

        JTextArea txtrConfirm = new JTextArea();
        txtrConfirm.setForeground(new Color(255, 255, 255));
        txtrConfirm.setBackground(new Color(255, 0, 153));
        txtrConfirm.setEditable(false);
        txtrConfirm.setFont(new Font("AR ESSENCE", Font.PLAIN, 25));
        txtrConfirm.setText("Please allow your waiter/waitress to enter         the confirmation number.");
        txtrConfirm.setBounds(54, 73, 407, 77);
        contentPanel.add(txtrConfirm);
        txtrConfirm.setLineWrap(true);

        textconfirmNumber = new JTextField();
        textconfirmNumber.setFont(new Font("AR ESSENCE", Font.PLAIN, 30));
        textconfirmNumber.setBounds(147, 148, 227, 47);
        contentPanel.add(textconfirmNumber);
        textconfirmNumber.setColumns(10);

        btnSubmit = new JButton("Submit");
        btnSubmit.setBackground(new Color(102, 51, 255));
        btnSubmit.setForeground(new Color(255, 255, 255));
        btnSubmit.setFont(new Font("AR ESSENCE", Font.PLAIN, 25));
        btnSubmit.setBounds(184, 211, 162, 29);
        contentPanel.add(btnSubmit);

    }
}
</code></pre>

<p>In this particular text field I only want it to accept the number 1234 in the text field.</p>