package myuml;


import javax.swing.text.PlainDocument;


/**
 * <p>Title: Hola a todos</p>
 *
 * <p>Description: este es el tutorial hola a todos</p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: Mi empresa</p>
 *
 * @author Mi nombre
 * @version 1.0
 */


public class FixedLengthPlainDocument extends PlainDocument
{

                        private int maxLength;

                        public FixedLengthPlainDocument(int maxLength) {
                                  this.maxLength = maxLength;
                        }
                        public void insertString(int offset, String str,
AttributeSet a)
                                throws BadLocationException {
                                if(getLength() + str.length() > maxLength) {

                                        Toolkit.getDefaultToolkit().beep();
                                }
                                else {
                                         super.insertString(offset, str, a);

                                }
                        }

            }

                public class FixedLengthTextField extends JTextField {

                        public FixedLengthTextField(int length)
                        {
                                this(null, length);
                        }

                        public FixedLengthTextField(String text, int length)
{
                                super(new FixedLengthPlainDocument(length),
text, length);
                        }
	        }
