爱心技术专栏专题

javaapplet源程序学习1

摘录:applet基础 来源:applet基础 加入时间:2006年09月29日
摘要:
javaapplet源程序学习1
java applet 源程序学习1
- Limit TextField input to a maximum length
import java.awt.*;
import java.awt.event.*;

public class TextFieldWithLimit extends TextField
    implements …

javaapplet源程序学习1

站点:爱心种子小博士 关键字:javaapplet源程序学习1
java applet 源程序学习1
- Limit TextField input to a maximum length
import java.awt.*;
import java.awt.event.*;

public class TextFieldWithLimit extends TextField
    implements KeyListener {
    private int  maxLength;
    public TextFieldWithLimit
           (String initialStr,int col,int maxLength) {
      super(initialStr,col);
      this.maxLength = maxLength;
      addKeyListener(this);
      }
    public TextFieldWithLimit (int col,int maxLength) {
      this("",col,maxLength);
      }
    public void keyTyped(KeyEvent e) {
      char c = e.getKeyChar();
      int len = getText().length();
      if (len < maxLength) {
         return;
         }
      else {
         if((c==KeyEvent.VK_BACK_SPACE)||
            (c==KeyEvent.VK_DELETE) ||
            (c==KeyEvent.VK_ENTER)||
            (c==KeyEvent.VK_TAB)||
             e.isActionKey())
            return;
          else {
            e.consume();
           }
          }
      }
    public void keyPressed(KeyEvent e) { }
    public void keyReleased(KeyEvent e) { }
    }
转载:转载请保留本信息,本文来自http://www.51dibs.com/lp07/la/a32/l_a_946c519a3ec6be99.html
关于我们 - 网站留言 - 友情链接 - 与我在线 - 与我聊天 - 领取红包 - TOP

客户服务中心信箱:[email protected] [email protected] 网站地图

声明

爱心赞助: