我有JTextfield
。现在我想在单击该组件时更改值。例如:分数(2 个大 JTextField
),当我单击其中一个字段时,它会将值从 0:0 增加到 1:0。
我应该实现MouseListener
还是有一些简单的方法可以做到这一点?在鼠标监听器中,我只需要重写一个方法 mouseClick
,其他方法将为空。
还有一个问题:我什么时候应该实现MouseListener
? e.getButton()
左按钮总是返回 1,右按钮总是返回 3?
最佳答案
Should I implement MouseListener or there is some easy way how I can do this? In mouse listner I need override just one method mouseClick and other method will be empty.
使用 MouseAdapter
。
An abstract adapter class for receiving mouse events. The methods in this class are empty. .. Extend this class to create a MouseEvent (including drag and motion events) or/and MouseWheelEvent listener and override the methods for the events of interest.
关于java - 单击鼠标时更改值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7869192/