import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.SwingUtilities; public class HelloWorld { public static void main(final String[] args) { System.out.println("executing main"); SwingUtilities.invokeLater(new Runnable() { public void run() { new HelloWorld(); } }); } public HelloWorld() { System.out.println("HelloWorld constructor"); final JFrame frame = new JFrame("HelloWorld"); frame.setLayout(new BorderLayout(20, 20)); JButton button = new JButton("Press Me"); button.setPreferredSize(new Dimension(200, 50)); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("about to construct JFileChooser"); JFileChooser fileChooser = new JFileChooser(); fileChooser.showOpenDialog(frame); } }); frame.add(button, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); } }