我正在处理一个项目,而使用active
的布尔我可以打印" active"虽然行动仍在进行(例如钥匙被按下)或者#34;不活跃"。我试图做到这一点,如果布尔值active
一次为真超过2秒(当它不再活动时重置"它会做其他事情。
代码:
public void upWasPerformed(boolean active) {//method thanks to MadProgrammer
if (active){
System.out.println("active");
}
else if (!active){
System.out.println("not active");
}
/**
*else if active is true for more than 2 secs, print "active for 2 secs"
*else if active is true for more than 4 secs, print "active for 4 secs"
*etc.
*/
}