import javax.swing.*;          
import java.awt.*;
import java.awt.event.*;

public class SwingApplication implements ActionListener {
   private static String labelPrefix = "Numero de Clicks: ";
   private int numClicks = 0;
   
   final JLabel label = new JLabel(labelPrefix + "0    ");
   
   //Valores Validos para a simulacao de aparencia....
   //(null = usar do sistema operacional atual), "Metal", "System", "Motif", "GTK+"
   final static String LOOKANDFEEL = null;
   
   public Component createComponents() {
      JButton button = new JButton("Clique-me!");
      button.setMnemonic(KeyEvent.VK_I);
      button.addActionListener(this);
      
      label.setLabelFor(button);
      
      JPanel pane = new JPanel(new GridLayout(0, 1));
      pane.add(button);
      pane.add(label);
      pane.setBorder(BorderFactory.createEmptyBorder(
                                                     30, //top
                                                     30, //left
                                                     10, //bottom
                                                     30) //right
                        );
      
      return pane;
   }
   
   public void actionPerformed(ActionEvent e) {
      numClicks++;
      label.setText(labelPrefix + numClicks);
   }
   
   private static void initLookAndFeel() {
      String lookAndFeel = null;
      
      if (LOOKANDFEEL != null) {
         if (LOOKANDFEEL.equals("Metal")) {
            lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
         } else if (LOOKANDFEEL.equals("System")) {
            lookAndFeel = UIManager.getSystemLookAndFeelClassName();
         } else if (LOOKANDFEEL.equals("Motif")) {
            lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
         } else if (LOOKANDFEEL.equals("GTK+")) { //new in 1.4.2
            lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
         } else {
            System.err.println("Unexpected value of LOOKANDFEEL specified: "
                                  + LOOKANDFEEL);
            lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
         }
         
         try {
            UIManager.setLookAndFeel(lookAndFeel);
         } catch (ClassNotFoundException e) {
            System.err.println("Não foi possivel encontrar a classe do Look and Feel:"
                                  + lookAndFeel);
            System.err.println("Usando o Look and feel padrao");
         } catch (UnsupportedLookAndFeelException e) {
            System.err.println("Não é possivel usar ("
                                  + lookAndFeel
                                  + ") nessa plataforma");
            System.err.println("Usando o Look and feel padrao");
         } catch (Exception e) {
            System.err.println("Não é possivel usar o Look and Feel ("
                                  + lookAndFeel
                                  + "), por alguma razao.");
            System.err.println("Usando o padrao");
            e.printStackTrace();
         }
      }
   }
   
   
   private static void createAndShowGUI() {
      //Chama o metodo acima para definir o Look and Feel automaticamente de acordo com a Plataforma
      initLookAndFeel();
      
      //Ativa as frescurinhas especificas da Swing
      JFrame.setDefaultLookAndFeelDecorated(true);
      
      //Cria a janela
      JFrame frame = new JFrame("SwingApplication");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      
      SwingApplication app = new SwingApplication();
      Component contents = app.createComponents();
      frame.getContentPane().add(contents, BorderLayout.CENTER);
      
      //Empacota e mostra.
      frame.pack();
      frame.setVisible(true);
   }
   
   public static void main(String[] args) {
      
      javax.swing.SwingUtilities.invokeLater(new Runnable() {
         public void run() {
            createAndShowGUI();
         }
      });
   }
}

