Programowanie obiektowe - JAVA
Informacje ogólne > Laboratorium 3 > Ćwiczenie 5 > Przykład 1. Interfejs implementowany w tej samej klasie (jak na poprzednim laboratorium)

Przykład 1. Interfejs implementowany w tej samej klasie (jak na poprzednim laboratorium)

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

public class Listener1 extends JFrame implements ActionListener {

  public Listener1() throws HeadlessException {
   
super();
    setDefaultCloseOperation(
EXIT_ON_CLOSE);
    setSize(300, 300);
    JButton b =
new JButton ("Zmien nazwe okna");
    b.addActionListener(
this);
    add(b);
    setVisible(
true);
   }

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

 public void actionPerformed(ActionEvent arg0) {
    setTitle(
"Nowa nazwa"
);
   }


}