Carnelian 0 Newbie Poster

In the following codes, I only specified the user to input only 4 numbers in the textfield. I want to output the numbers inputted by the user but I don't know how to do it seeing that the "text" and "value" is different in a formattedtextfield. All I see in some guides is using a NumberFormat and when it comes to using MaskFormatter the guide doesn't indicate how to process the input from user... I need help >.<

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.text.*;

public class FormatTest extends JFrame implements ActionListener
{
	public static void main(String[] args)
	{
		FormatTest tst=new FormatTest();
	}
	
	public FormatTest()
	{
		JFrame frame=new JFrame("Test");
		JPanel panel=new JPanel();
		MaskFormatter formatter=null;
		try
		{
			formatter=new MaskFormatter("####");
		}catch(java.text.ParseException e){}
		JFormattedTextField field=new JFormattedTextField(formatter);
		field.setColumns(5);
		field.addActionListener(this);
		frame.getContentPane().add(panel);
		panel.add(field);
		frame.pack();
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	public void actionPerformed(ActionEvent a)
	{
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.