Java:JRadioButton上的ActionEvent和ItemEvent有什么区别? [英] Java: What's the difference between ActionEvent and ItemEvent on a JRadioButton?

查看:264
本文介绍了Java:JRadioButton上的ActionEvent和ItemEvent有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它们都在释放鼠标按钮后被提升一次,并且两者都可以在JRadioButton上获得所有可用的信息,对不对?有什么区别吗?

They're both raised once after the mouse button is released and both can have all the information available on the JRadioButton right? Is there any difference?

推荐答案

一个 ActionListener 当用户与按钮互动时,会调用手(但可以通过

An ItemListeners are notified when ever the state of the button is changed, whether through a user interacting with the button or programmatically (via the setSelected method). ActionListeners on the other hand will be called when a user interacts with the button (but can be simulated programmatically via the onClick method).

请注意,与按钮交互(例如单击或击中空格键)的用户也将更改按钮的状态,并引发项目事件和动作事件.通常,您将要定义一个或另一个,不要同时听按钮上的动作事件和项目事件.

Note that a user interacting with the button such as clicking or hitting the space bar will also change the state of the button and raise an item event as well as an action event. Generally, you will want to define either one or the other, don't listen for both action events and item events on the button.

这篇关于Java:JRadioButton上的ActionEvent和ItemEvent有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆