java - 单击鼠标时更改值

标签 java swing mouselistener

我有JTextfield。现在我想在单击该组件时更改值。例如:分数(2 个大 JTextField),当我单击其中一个字段时,它会将值从 0:0 增加到 1:0。

我应该实现MouseListener还是有一些简单的方法可以做到这一点?在鼠标监听器中,我只需要重写一个方法 mouseClick ,其他方法将为空。

还有一个问题:我什么时候应该实现MouseListenere.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/

相关文章:

java - 如何在 Jar 文件中读取/写入 .dat 文件?

java - Spring 安全 : How to redirect to a REST url after login

java - 如何在桌面应用程序中添加 Google 搜索框?

java - 向 JComboBox 和 JTextField 添加标签

java - 实时监听JFrame高宽

java - 带有 MouseListener 的 CardLayout 不起作用

java - 通过 Activity 传递值观

Java 突然停止写入 ArrayList

java - JFrame 找不到 'pack' 方法

java - 如何监听子组件?