gpt4 book ai didi

java - 有没有办法让 ActionListener 取消?

转载 作者:行者123 更新时间:2023-12-01 14:37:45 25 4
gpt4 key购买 nike

我有一个操作监听器,如果变量值为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com