import java.awt.*; import java.awt.event.*; import javax.swing.*; public final class Main extends JDialog implements WindowListener, ActionListener { private final JLabel lbl = new JLabel("Press the button to open a simple file chooser:"); private final JButton btn = new JButton("Open!"); public static void main(String args[]) { new Main().runDialog(); } public Main() { getContentPane().add(lbl, BorderLayout.NORTH); getContentPane().add(btn, BorderLayout.CENTER); btn.addActionListener(this); addWindowListener(this); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ex) { ex.printStackTrace(); } } private void runDialog() { Font currFont = btn.getFont(); pack(); btn.setFont(currFont.deriveFont((float)(currFont.getSize() * 3.0d))); pack(); setVisible(true); } public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.showOpenDialog(null); } public void windowClosing(WindowEvent e) { dispose(); System.exit(1); } public void windowOpened(WindowEvent windowevent) { } public void windowIconified(WindowEvent windowevent) { } public void windowDeiconified(WindowEvent windowevent) { } public void windowDeactivated(WindowEvent windowevent) { } public void windowClosed(WindowEvent windowevent) { } public void windowActivated(WindowEvent windowevent) { } }