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

class EventHandler {
    private JLabel label;
    EventHandler(JLabel l) {
        label = l;
    }

    public void actionA(ActionEvent e) {
        label.setText("Toll! Knopf 1 mit Label "+e.getActionCommand());
    }
    public void actionB(ActionEvent e) {
        label.setText("Toll! Knopf 2 mit Label "+e.getActionCommand());
    }
}


public class SeveralButtonsLambda extends JFrame {
    JLabel  label;
    JButton butA, butB;
    EventHandler handler;

    public static void main(String args[]) {
        new SeveralButtonsLambda();
    }
    public SeveralButtonsLambda() {
        setLayout(new FlowLayout()); 
        setSize(500,100);
        setVisible(true);
        setFont(new Font("SansSerif", Font.BOLD, 18));
        label = new JLabel();
        label.setText("Press key...");
        add(label);
        handler = new EventHandler(label);
        butA = new JButton("Knopf A");
        butA.addActionListener(handler::actionA);
        add(butA);
        butB = new JButton("Knopf B");
        butB.addActionListener(e->label.setText("Toll"+e.getActionCommand()));
                               //handler::actionB);
        add(butB);
    }
}
