// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.awt.*;
import java.awt.event.*;

public class MaxText extends Frame implements TextListener {
    private TextField tf;

    public MaxText() {
        setSize(100, 100);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        tf = new TextField();
        tf.addTextListener(this);
        add(tf);
    }

    public void textValueChanged(TextEvent e) {
        if(tf.getText().length() > 5) {
            tf.setText(tf.getText().substring(0, 5));
        }
    }
    public static void main(String[] args) {
        MaxText f = new MaxText();
        f.show();
    }
}
