作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个小游戏,我需要使用 isShiftDown 两次,第一次当他使用 Shift+click 时,一个框变成绿色,当他第二次在同一个框上 Shift+click 时,她会改变颜色,变成红色。这就是我所做的,但它不起作用,事实上,我第一次 Shift+单击一个框时,她变成绿色((字节)6),但我不知道如何第二次 Shift+单击。
boolean count = false;
public synchronized void mouseClicked(MouseEvent e) {
synchronized (gameModel) {
int width = getGameX(e) ;
int height = getGameY(e) ;
if (e.isShiftDown() && count == false){
gameModel.set(width, height, (byte)6);
count = true;
}
if (e.isShiftDown() && count == true){}
else {
byte c = (byte)1 ;
gameModel.set(width,height,c);
}
notify(gameModel) ;
}
最佳答案
您的第一个 if
block 将 count
设置为 true。您的第二个 if
block 检查 count
是否为 true(这肯定是,因为您刚刚将其设置为 true),因此 else block 永远不会触发。
也许你的意思更像是这样的:
if (e.isShiftDown() && !count){
gameModel.set(width, height, (byte) 6);
count = true;
} else if (e.isShiftDown()) {
byte c = (byte) 1;
gameModel.set(width,height,c);
}
关于java - 使用 isShiftDown() 两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34232411/
我正在开发一个小游戏,我需要使用 isShiftDown 两次,第一次当他使用 Shift+click 时,一个框变成绿色,当他第二次在同一个框上 Shift+click 时,她会改变颜色,变成红色。
所以我正在构建一个 sphinx-4 程序,它仅在您按住 Shift 按钮时才会监听。这样我就可以防止错误,并且只有当我按住 Shift 按钮时才让它听我的。当我释放 Shift 按钮时,我希望程序等
大家好 我有一个 JFrame,我已经向该 JFrame 添加了一个 JButton。 我还向我的 JButton 添加了一个 ActionListener。 现在请将此伪代码转换为 Java: pu
我是一名优秀的程序员,十分优秀!