Latest News

 










Adapter Example

Previous slide Next slide Back to first slide View graphic version


Adapter Example


 
My other sites

Latest News

 










Adapter Example

  • Adapter classes are used in awt for event handling :

    Button okButton = new Button(“OK”);

    okButton.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent evt) {

    oldFile.renameTo(newFile);

    }

    } );

    add(okButton);

  • The WindowListener interface declares 7 methods that provide notification about 7 different kinds of events. Often, only one or two of these events are of interest. An adapter class that subclasses WindowAdapter needs to implement only the methods of interest. The rest have empty implementations :

    addWindowListener(new WindowAdapter() {

    public void windowClosing(WindoEvent e) {

    System.exit(0);

    }

    } );

Previous slide Next slide Back to first slide View graphic version