Programowanie obiektowe - JAVA
Informacje ogólne > Laboratorium 3 > Ćwiczenie 5 > Przykład 2. Interfejs implementowany w wewnętrznej klasie anonimowej.

Przykład 2. Interfejs implementowany w wewnętrznej klasie anonimowej.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Listener2 extends JFrame {

   public Listener2() throws HeadlessException {
     
super();
      setDefaultCloseOperation(
EXIT_ON_CLOSE);
      setSize(300, 300);
      JButton b =
new JButton ("Zmien nazwe okna");
           
       b.addActionListener(
new ActionListener() {
                          
public void
actionPerformed(ActionEvent arg0) {
                                setTitle(
"Anonimowa klasa wewnetrzna"
); 
                           }

        });

       add(b);
       setVisible(
true);
    }

   public static void main(String[] args) {
    
new Listener2();
   }
}