WindowAdapter In Inner Class

前端 未结 2 1919
梦毁少年i
梦毁少年i 2021-01-28 13:56

I\'m working on a Java school assignment, thought I had it all finished, but then went over the requirements one more time and realized I overlooked a specific requirement and n

2条回答
  •  故里飘歌
    2021-01-28 14:29

    looks like you got everything right!

    Now what I assume your teacher means is: the handler should be an instance (not "object") of an inner class that extends the WindowAdapter class.

    By doing the following:

    new WindowAdapter() {
    
        // Use annotations, it's useful :)
        @Override
        public void windowCloses(WindowEvent e) {
            // ...
        }
    }
    

    ... you're actually creating a new anonymous class that extends WindowAdapter. In this new definition, you override the WindowAdapter#windowCloses method, then you instantiate it in a new object that you pass as an argument to addWindowListener.

    Apparently, your teacher expects you to actually define an inner class and create a new instance of it. I don't wanna just give you the code for this but you're god damn close, you'll figure it out in an instant!

提交回复
热议问题