windowlistener - Cannot downcast an Object into Frame in Java Window Event handling -
i learning basic event handling in java.
i working on frame closing method (implemented windowlistener). understand getsource() call returns object actual event taking place. when downcast window, works fine when downcast 1 more level below (to frame), doesn't work , gives error- frame cannot resolved type
in main class, extending frame.
@override public void windowclosing(windowevent e) { object objsource= e.getsource(); //window objwindow = (window)objsource; - works fine frame objwindow = (frame)objsource; //- why doesn't work objwindow.dispose(); }
unfortunately import java.awt.frame; package not imported in code hence giving error in closing frame window. above code works both frame , window call.
Comments
Post a Comment