if(jTextUrl1.getText().trim().compareTo("")==0)
改为
if("".equals(jTextUrl1.getText().trim()))看看
改为
if("".equals(jTextUrl1.getText().trim()))看看
解决方案 »
- 求高效解析URL参数的算法
- 关于 System.out代码的疑问
- 如何用java画一棵二叉树
- 调用自定义异常类的问题。
- 关于JAVA的配置问题
- Directory Dialog box
- Long.toHexString是不是有个BUG?
- 我想在html中输入查询关键字,对数据库进行查询,显示在jsp中,帮我看看哪错了?
- 关于java网络编程的问题 如何传递一个有图片,有声音的网页给一个本地端口!!!SOS!!!
- Java文件在windows编译后的class,放到linux上运行乱码
- ??请问有谁做过用户登录的模块?????
- 我写了一个Applet小程序(用JBuilder5),运行正常,但是……
public String getText()
Returns the text contained in this TextComponent. If the underlying document is null, will give a NullPointerException.
Returns:
the text
See Also:
setText(java.lang.String)应该为
String str = jTextUrl1.getText();
if(str == null && "".equals(str.trim()))
我按完对话框的ok,马上再弹出来一个
我按完对话框的ok,马上再弹出来一个
现在程序结果和我目的不同了,没来得及重新输入又回到focusLost方法里面了,
当然jTextUrl1的内容依然是""
那么就弹个对话框出来,你总不能把人家原来输入的
东西给去掉,换上一个自己合法的default值吧
不然对话框又会总是跳出来
上排没有空,所以
The order of listener calls is not defined by the JavaBean specification
There are two exceptions to this rule:Constrained properties in a JavaBean talk to VetoableChangeListeners. The order of called listeners is not defined, but if any listener throws a PropertyVetoException, the remaining ones are not called.
If you write your own events (under the Beans model, same type of pattern as existing AWT events), their behavior is defined by you. You can implement and document that they have a certain order or will stop when any listeners throw an exception.
I strongly recommend against this as it's not normal behavior for event handlingNote that you cannot simply make the text property constrained. The problem is that the setText method for a constrained JTextField could throw a PropertyVetoException, which isn't declared in the setText method of JTextField.There are really two things you can do here: You could write a custom event for this, and implement/document that it calls listeners in the added order and that if any throw an exception, the others are not called.
Add a single focusLost listener that does the multiple validations in order, stopping if any fail.
I'd recommend the second approach, like the following:
JTextField f = new JTextField();
f.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {}
public void focusLost(FocusEvent e) {
try {
validation1();
validation2();
validation3();
}
catch(Exception e) {
// report the validation error
}
}
});If any of the validations fail (throw an exception), the others are not processed.Finally, Don't forget that a call to setText() can change the value of the field!. You should override setText() and include validation as well.
真的必须这样做吗?这东西是你写的吗?原来你的e文那么厉害!!