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

public class SeveralButtons extends JFrame implements
                                       ActionListener {
    JLabel label;
    JButton butA, butB;
    public SeveralButtons() {
        setLayout(new FlowLayout()); 
        setSize(500,100);
        setVisible(true);
        setFont(new Font("SansSerif", Font.BOLD, 18));
        label = new JLabel();
        label.setText("Press key...");
        add(label);
        butA = new JButton("Knopf A");
        butA.setActionCommand("1");
        butA.addActionListener(this);
        add(butA);
        butB = new JButton("Knopf B");
        butB.setActionCommand("2");
        butB.addActionListener(this);
        add(butB);
    }
    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("1")) {
            label.setText("Toll! Knopf 1 mit Label "+
                  ((JButton)e.getSource()).getText());
        } else {
            label.setText("Toll! Knopf 2 mit Label "+
                  ((JButton)e.getSource()).getText());
        }
        System.out.println(e);
    }
    static class MyRunnable implements Runnable {
        public void run() {
            new SeveralButtons();
        }
    }
    public static void main(String args[]) {
        SwingUtilities.invokeLater(new MyRunnable());
}   }
