单击布尔值更改按钮
每次用户按下某个按钮时布尔值会发生变化,最简单的解决方案是什么?我的按钮操作监听器中唯一的事情就是调用某个方法,例如 Method1(); 或者使用 int 会是一个更可行的解决方案吗?
谢谢。
What would be the most simple solution each time a user presses a certain button the bool value changes? The only thing in my button action listener would be a call to a certain method for example Method1();
Or would working with a int be a more viable solution?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
更简单:
Even simpler:
在类中的字段上有一个标志变量。
示例:
在您的方法中执行以下操作:
Have a flag variable on the fields in your class.
Example:
in your method do:
对于这种情况,我建议使用 JToggleButton 或 JCheckBox。这对用户来说会更自然,并且任何一个组件都可以存储其状态而无需声明任何进一步的布尔值。
例如
I would recommend using a JToggleButton or JCheckBox for this case. It would be more natural to the user and either component can store it's state without declaring any further booleans.
E.G.
我认为这正是您所寻找的!希望有帮助。
I think this is exactly what your looking for!! Hope it helps.