JVM在用户点击单选按钮时生成哪种事件类型?是操作事件还是项事件?

huangapple go评论73阅读模式
英文:

Which event type does JVM generate when a user clicks a radio button? Is it an action event or an item event?

问题

我对Swing组件相当新。然而,我看过许多示例,其中单选按钮实现了actionListener和itemListener。在这种情况下,哪种处理事件的方式是正确的呢?

英文:

I am fairly new to swing components. However, I have seen many examples where a radio button implements actionListener as well as itemListener. Which one is the correct way of handling events in such a case?

答案1

得分: 2

当用户点击单选按钮时,JVM 会生成哪种事件类型?它是操作事件还是项事件?

这取决于已连接到单选按钮的监听器!例如,AbstractButton.addActionListener(ActionListener) 和/或 addItemListener(ItemListener) 中的一个或两个。

另外: 对于这个情况,我建议使用 ActionListenerItemListener 会在选择 ButtonGroup 中的按钮时产生两个事件。其中一个事件是刚刚被取消选择的项的事件。

英文:

> Which event type does JVM generate when a user clicks a radio button? Is it an action event or an item event?

It depends which listener(s) has(/have) been attached to the radio buttons! E.G. Either or both of AbstractButton.addActionListener(ActionListener) / addItemListener(ItemListener).

Aside: for this I'd recommend an ActionListener.<br>The ItemListener will produce two events when a button in a ButtonGroup is selected. One of the events is for the item which just got deselected.

huangapple
  • 本文由 发表于 2020年9月10日 11:25:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/63822383.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定