当前位置: 技术问答>java相关
如何在控件失去焦點時觸發一個事件??
来源: 互联网 发布时间:2015-05-28
本文导语: 我想在JTextField失去焦點時判斷jTextField1是否為空,為空,則彈出警告框. 應該如何實現?? | 呵呵!忘了提醒你了,你试试这个! jTextField1.addFocusListener(new FocusAdapter(){ public void focusLost(Foc...
我想在JTextField失去焦點時判斷jTextField1是否為空,為空,則彈出警告框.
應該如何實現??
應該如何實現??
|
呵呵!忘了提醒你了,你试试这个!
jTextField1.addFocusListener(new FocusAdapter(){
public void focusLost(FocusEvent e){
if(e.isTemporary()) return;
if (jTextField1.getText().length()==0){
JOptionPane.showMessageDialog(null,"ad","",JOptionPane.DEFAULT_OPTION);
}
}
});
jTextField1.addFocusListener(new FocusAdapter(){
public void focusLost(FocusEvent e){
if(e.isTemporary()) return;
if (jTextField1.getText().length()==0){
JOptionPane.showMessageDialog(null,"ad","",JOptionPane.DEFAULT_OPTION);
}
}
});
|
addFocusListener(FocusListener fl);
class fl implements FocusListener
{
public focusGained(FocusEvent e)
{
}
public focusLost(FocusEvent e)
{
}
}
class fl implements FocusListener
{
public focusGained(FocusEvent e)
{
}
public focusLost(FocusEvent e)
{
}
}