import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MyFrame2 extends JFrame implements ActionListener { public MyFrame2 () { super ("Mein Fenster"); Container rootContainer = getContentPane(); FlowLayout flow = new FlowLayout(FlowLayout.LEFT); rootContainer.setLayout(flow); JButton button = new JButton("Klick mich"); rootContainer.add(button); MyActionListener mal = new MyActionListener (); button.addActionListener (this); } public void actionPerformed (ActionEvent e){ System.out.println("Action performed wurde aufgerufen im Frame"); } public static void main (String args[]) { JFrame frame = new MyFrame2(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setSize(300,200); frame.show(); } }