Do you need to add unrealized methods?

I am trying to add a listener to a close operation JFrame:

addWindowListener(new WindowListener() {
    @Override
    public void windowClosing(WindowEvent e) {
        setVisible(false);
    }
});

The fact is that Eclipse keeps telling me that I have to “add unrealized methods”, which I believe is getting from WindowListener. However, I am confused, why do you need to implement all these other methods if you only need to override them? And if I add all these other methods, but don’t put any content in them, for example.

@Override
public void windowActivated(WindowEvent e) {}

will the default behavior for this method be lost? Or will it only get more complicated if I write something inside the method?

+4
source share
3 answers

, . .

WindowAdapter WindowListener

addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosing(WindowEvent e) {
        setVisible(false);
    }
});

WindowAdapter - , WindowListener , .

PS: . . MouseAdapter, KeyAdapter

+6

, .

: , . 5 , 5 .

Adapter : , , .

WindowListener WindowAdapter. , WindowListener ( ) WindowAdapter , .

+4

, ( ).

, , , .

() , , .

, , , " " , .

0

Source: https://habr.com/ru/post/1622712/


All Articles