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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -