import javax.swing.*; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class App extends JFrame implements ActionListener { public static void main(String args[]) { App j = new App(); } public App() { this.getContentPane().setLayout(new FlowLayout()); button = new JButton("Hello"); button.addActionListener(this); this.getContentPane().add(button); label = new JLabel(); this.getContentPane().add(label); this.pack(); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent e) { if (e.getSource() == button) { label.setText("World"); this.pack(); } } JButton button; JLabel label; }