Two Laptop Bag
The moose likes Swing / AWT / SWT and the fly likes Event Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Event Handling" Watch "Event Handling" New topic

Event Handling

kedar parundekar
Ranch Hand

Joined: May 10, 2006
Posts: 40
I know,
1)The underlying OS is constantly monitoring events
2)When a event occurs, the OS reports these events to the programs that are running.

Q)How OS reports these events to programs that are running? Is there any OS event also?
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46375
If I remember correctly the devices (eg mouse, keyboard) send messages whenever their state changes; these are called interrupts, and they are handled by hardware using a device called an exception handler, which does not mean the same as the term in Java programming.

Presumably somehow the OS tells the JVM that there has been an event at pixel no (500, 400) and it was a mouse click. The JVM then works out from its position that it was in the area occupied by your exitButton, and exitButton then sends an ActionEvent to whichever Listener(s) is(are) registered to it. The Listener then receives the ActionEvent into its actionPerformed() method, and you know the rest.

Anybody able to give a better explanation???

I agree. Here's the link:
subject: Event Handling
It's not a secret anymore!