import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JTextArea; import java.awt.BorderLayout; import java.awt.GridLayout; public class SwingExample extends JFrame implements Runnable { public SwingExample() { //initalize any state here. super("Swing Example"); } public void run() { setSize(500,400); getContentPane().setLayout(new BorderLayout()); JButton b = new JButton("Clear!"); JTextArea jta = new JTextArea(); b.addActionListener( e -> jta.setText("")); getContentPane().add(BorderLayout.NORTH, b); getContentPane().add(BorderLayout.CENTER, jta); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); } public static void main(String[] args) { //don't modify this other than changing the //class name in the first line. It ensures //thread sanity. SwingExample c = new SwingExample(); javax.swing.SwingUtilities.invokeLater(c); } }