import javax.swing.*; import java.awt.event.*; class ButtonListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "You pushed the button!!"); } } public class LookAndFeels { public static void main(String[] args) { // list all of the look and feel options we have UIManager.LookAndFeelInfo[] options = UIManager.getInstalledLookAndFeels(); for (UIManager.LookAndFeelInfo option : options) { System.out.println(option.getClassName()); } // set the look and feel try { // this attempts to pick the best look and feel for the user's system UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception ignored) { System.out.println("Could not set the look and feel."); // we could also try and set a second option here } // create and set up the window. JFrame frame = new JFrame("Button Example!"); // make the program close when the window closes frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // add a button object JButton button = new JButton("Push Me!"); button.addActionListener(new ButtonListener()); frame.getContentPane().add(button); // display the window. frame.pack(); frame.setVisible(true); } }