JTextField的问题 如何限制JTextField中不能输入汉字? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一个比较笨,但很管用的方法,截获键盘事件/内容变更事件,调用检测内容是否为汉字的代码请参考 :如何运用java来校验一段字符串是否为汉字 public static boolean isGB2312(String str) { char[] chars = str.toCharArray(); boolean isGB2312 = false; for (int i = 0; i < chars.length; i++) { byte[] bytes = ("" + chars).getBytes(); if (bytes.length == 2) { int[] ints = new int[2]; ints[0] = bytes[0] & 0xff; ints[1] = bytes[1] & 0xff; if (ints[0] >= 0x81 && ints[0] <= 0xFE && ints[1] >= 0x40 && ints[1] <= 0xFE) { isGB2312 = true; break; } } } return isGB2312; }进制间转换没大看懂 :( 可以利用common-lang-2.3.jar包中的StringUtils.isAsciiPrintable()来判断 public static boolean isGB2312(String str) { char[] chars = str.toCharArray(); boolean isGB2312 = false; for (int i = 0; i < chars.length; i++) { byte[] bytes = (chars + "").getBytes(); if (bytes.length == 2) { int[] ints = new int[2]; ints[0] = bytes[0] & 0xff; ints[1] = bytes[1] & 0xff; if (ints[0] >= 0x81 && ints[0] <= 0xFE && ints[1] >= 0x40 && ints[1] <= 0xFE) { isGB2312 = true; break; } } } return isGB2312; }我试一下,好像什么都会输出false 呼唤牛人!!急!!!!重定向后,cookie丢失怎么办? 比较中,发现差距真大哦 大家看我 理解JavaBean对不对 ? 如何用Java编程模拟一个网络,并监测其丢包率? scjp 关于main的问题 对内部类的不解 关于jar文件数字签名的问题 一个import的问题: 我想学习java应该怎样入手.请教一下高兴.指点一二. 怎样用javascript编程实现文件下载功能? 问一个关于日期的算法,谢谢了,帮帮忙????????? java 使用socket编写简单聊天程序问题?
调用检测内容是否为汉字的代码
请参考 :如何运用java来校验一段字符串是否为汉字
char[] chars = str.toCharArray();
boolean isGB2312 = false;
for (int i = 0; i < chars.length; i++) {
byte[] bytes = ("" + chars).getBytes();
if (bytes.length == 2) {
int[] ints = new int[2];
ints[0] = bytes[0] & 0xff;
ints[1] = bytes[1] & 0xff;
if (ints[0] >= 0x81 && ints[0] <= 0xFE && ints[1] >= 0x40 && ints[1] <= 0xFE) {
isGB2312 = true;
break;
}
}
}
return isGB2312;
}进制间转换没大看懂 :(
char[] chars = str.toCharArray();
boolean isGB2312 = false;
for (int i = 0; i < chars.length; i++) {
byte[] bytes = (chars + "").getBytes();
if (bytes.length == 2) {
int[] ints = new int[2];
ints[0] = bytes[0] & 0xff;
ints[1] = bytes[1] & 0xff;
if (ints[0] >= 0x81 && ints[0] <= 0xFE && ints[1] >= 0x40 && ints[1] <= 0xFE) {
isGB2312 = true;
break;
}
}
}
return isGB2312;
}我试一下,好像什么都会输出false