import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MeinFrame extends JFrame{ private JLabel jlabel; private JButton jButton; private int klicks; public MeinFrame() { setTitle("TestFrame"); jlabel = new JLabel("Klicks: " + klicks); jButton = new JButton("Drück mich"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().add(jlabel, BorderLayout.LINE_START); getContentPane().add(jButton, BorderLayout.PAGE_END); jButton.addActionListener(new buttonListener()); pack(); setVisible(true); } class buttonListener implements ActionListener{ public void actionPerformed(ActionEvent e){ klicks++; jlabel.setText("Klicks: " + klicks); } } public static void main(String[] args){ new MeinFrame(); } }