Java如何控制用户输入的长度,用Java Applet 进行Web编程时,如何限制输入域中可输入字符的长度!解决后马上给分!!!...
用Java?Applet?進行Web編程時,如何限制輸入域中可輸入字符的長度!解決后馬上給分!!!
|
create?a?new?class?FixLengthDocument?extends?PlainDocument,?override?public?void?insertString(int?offs,?String?str,?AttributeSet?a)?throws?BadLocationException
to?check?string?length,?for?full?example,?see?the?following?code?snippet.
import?java.awt.*;
import?javax.swing.*;
import?java.util.*;
import?javax.swing.text.*;
import?java.awt.event.*;
public?class?TimeControl?extends?JPanel
{
private?FixLenthTextField?inYear;
private?FixLenthTextField?inMonth;
private?FixLenthTextField?inDay;
private?FixLenthTextField?inHour;
private?FixLenthTextField?inMinute;
private?FixLenthTextField?inSecond;
private?JLabel?sDeli;
public?TimeControl()
{
createControl();
}
public?void?setColor(Color?bkclr,Color?foreclr)
{
super.setBorder(BorderFactory.createEmptyBorder());
super.setBackground(bkclr);
Container?c=this;
Component[]?components=c.getComponents();
if(components==null)
return;
int?num=components.length;
for(int?i=0;i0)
{
if(len>0)
{
len--;
scontent=scontent.substring(0,len);
if(isValidValue(scontent)>=0)
{
break;
}
}
else
break;
}
super.remove(0,super.getLength());
if(scontent!=null)
super.insertString(0,scontent,a);
}
protected?void?doBeep()
{
Toolkit.getDefaultToolkit().beep();
}
}
}
}
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Java如何控制用户输入的长度,用Java Applet 进行Web编程时,如何限制输入域中可输入字符的长度!解决后马上给分!!!...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何给电脑设置默认浏览器如何在电脑设置默
- 下一篇: java美元兑换,(Java实现) 美元