import java.awt.*; // Abstract Window Toolkit import java.awt.event.*; import javax.swing.*; class Ex { public static void main(String[] args) { JFrame window = new JFrame("Tittel"); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); window.add(panel); JLabel text = new JLabel("Example text"); panel.add(text); JButton button = new JButton("Button text"); panel.add(button); window.pack(); window.setVisible(true); class ButtonAction implements ActionListener { @Override public void actionPerformed(ActionEvent e) { button.setText("Pressed"); } } button.addActionListener(new ButtonAction()); } }