   import java.awt.*;
   import java.awt.event.*;
   import javax.swing.*;

   public class ButtonTest extends JFrame {
      private JButton plainButton, fancyButton;

     private ButtonTest()
     {
        Container c = getContentPane();
       c.setLayout( new FlowLayout() );

       Icon bug1 = new ImageIcon( "bug1.gif" );
       Icon bug2 = new ImageIcon( "bug2.gif" );

        plainButton = new JButton( "Plain Button",bug2 );
        c.add( plainButton );
        plainButton.setRolloverIcon( bug1 );

        fancyButton = new JButton( "Fancy Button", bug1 );
        fancyButton.setRolloverIcon( bug2 );
       c.add( fancyButton );

        ButtonHandler x = new ButtonHandler();
        fancyButton.addActionListener( x );
        plainButton.addActionListener( x );

        setSize( 275, 100 );
        show();
     }

     public static void main( String args[] )
     {
        ButtonTest app = new ButtonTest();

      app.addWindowListener(
          new WindowAdapter() {
              public void windowClosing (WindowEvent e )
              {
                 System.exit( 0 );
             }
          }
        );
     }

     // inner class for button event handling
     private class ButtonHandler implements ActionListener {
        public void actionPerformed( ActionEvent e )
        {
           JOptionPane.showMessageDialog( null,
              "You pressed: " + e.getActionCommand() );
        }
     }
  }
