Event Handling for Frame and JFrame

The following example demonstrates Java event handling for both JFrame and Frame. It also shows how to treat the two classes polymorphically.

Create a Listener class by extending the j ava . awt. event. WindowLi stener interface. from java.awt.event import WindowListener class Listener (WindowListener):

def windowOpened(self, windowEvent):

self.handleEvent("windowOpened",windowEvent) def windowClosed(self, windowEvent):

self.handleEvent("windowClosed", windowEvent) def windowClosing(self, windowEvent):

self.handleEvent("windowClosing",windowEvent) def WindowActivated(self, windowEvent):

self.handleEvent("WindowActivated", windowEvent) def windowDeactivated(self, windowEvent):

self.handleEvent("windowDeactivated", windowEvent) def windowIconified(self, windowEvent):

self.handleEvent("windowlconified", windowEvent) def windowDeiconified(self, windowEvent):

self.handleEvent("windowDeiconified", windowEvent) def handleEvent(self, event_name, event): print "Event: " + event_name print "Event info: " + 'event.class" print "Source: " + ,event.source.title> print "-----------------"

Was this article helpful?

0 0

Post a comment