• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Event handling

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when we talk of GUI,we say that whenever a user performs any action i.e presses - releases a button or press any key or mouse motion,it is an event which is represented in java as event object. I am confused about how to classify these events, whether it's an ActionEvent or ItemEvent or WindowEvent,MouseEvent...etc..etc???
when we click on 'button' component, it generates Actionevent and we implement ActionListener interface, but if we click on checkbox ,we implement ItemListener since it generates ItemEvent, why so? I'm so confused...!!!
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
many components fire off numerous events.

if you click on a component it may fire off:
focusGained event
action event
mouse pressed event
mouse released event
mouse clicked event
etc
etc

you have to choose what you want to listen for.

eg you mention JCheckBox and ItemListener.
You could instead add an ActionListener and it will do pretty much the same thing,
but if you just want to know when the checkbox is selected, it's easier to use
ItemListener/ItemEvent/getStateChange() == ItemEvent.SELECTED
and you will only get the event where it has been selected, not for deselection
(and you can single out the deselection event as well).

and, you can also build all of this behavior into your actionListener code,
so you're probably more confused than before.
 
Your mother is a hamster and your father smells of tiny ads!
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic