Limit a TextField to UppercaseTag(s): AWT


[JDK1.1]
import java.awt.*;
import java.awt.event.*;

public class UpperTF extends Frame {
  public static void main(String argv[]) {
    new UpperTF().setVisible(true);
  }
  
  public UpperTF() {
    setLayout(new FlowLayout());
    TextField tf = new TextField(10);
    add(tf);  
    tf.addKeyListener(
      new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            if (Character.isLetter(e.getKeyChar())) 
                e.setModifiers(Event.SHIFT_MASK);
             }
      });
    pack();
    
    addWindowListener(
      new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
            }
          }
    );
    }
    
  public Dimension getPreferredSize() {
    return new Dimension(200,200);
    }
}

blog comments powered by Disqus