作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个操作监听器,如果变量值为 null
,我想取消该操作监听器的当前迭代。
public class ValidateListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
myCalendarKey mCal = Project5.verifyDate(month+"/"+day+"/"+year); //month day and year are defined, just not in this code display.
if (mCal == null) e.cancel(); //I need something to cancel the current ActionEvent if this returns true.
/* A lot more code down here that only works if mCal is defined */
}
}
我想我可以使用 if-else 语句并使其在 mCal != null
时执行所有操作,如果 mCal == null
则不执行任何操作,但是有吗有更好的方法吗?
最佳答案
我认为您正在寻找的是:
e.consume()
这将消耗该事件: http://docs.oracle.com/javase/6/docs/api/java/awt/AWTEvent.html#consume()
关于java - 有没有办法让 ActionListener 取消?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16320757/
我是一名优秀的程序员,十分优秀!