最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
java applet 源程序学习1
时间:2022-07-02 17:24:19 编辑:袖梨 来源:一聚教程网
- 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) { }
}
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) { }
}
相关文章
- 《潜行者2:切尔诺贝利之心》使用手电筒方法介绍 11-21
- 《潜行者2:切尔诺贝利之心》回声探测器使用攻略分享 11-21
- 《潜行者2:切尔诺贝利之心》人工制品奖励获得方法介绍 11-21
- 《潜行者2:切尔诺贝利之心》奇美拉嵌合体打法技巧分享 11-21
- 《潜行者2:切尔诺贝利之心》风衣怪打法技巧分享 11-21
- 《潜行者2:切尔诺贝利之心》变异狗打法技巧分享 11-21