import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class GuiImageButtonSample extends JFrame implements ActionListener
{
private static final int FRAME_WIDTH = 440;
private static final int FRAME_HEIGHT = 270;
private static final int FRAME_X_ORIGIN = 100;
private static final int FRAME_Y_ORIGIN = 150;
private static final int BUTTON_WIDTH = 80;
private static final int BUTTON_HEIGHT = 30;
private JButton myJButton;
public GuiImageButtonSample( )
{
Container contentPane = getContentPane();
setTitle ("Pics");
setSize (FRAME_WIDTH, FRAME_HEIGHT);
setLocation (FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
setResizable(false);
contentPane.setLayout(null);
contentPane.setBackground(Color.white);
myJButton = new JButton(new ImageIcon("spike.gif"));
myJButton.setPressedIcon(new ImageIcon("austin_powers.gif"));
myJButton.setRolloverEnabled(true);
myJButton.setRolloverIcon(new ImageIcon("magoo.gif"));
myJButton.setContentAreaFilled(false);
myJButton.setFocusPainted(false);
myJButton.setBorderPainted(false);
myJButton.setBounds(170,50,100,100);
contentPane.add(myJButton);
myJButton.addActionListener(this);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent event)
{
JButton clickedButton = (JButton) event.getSource();
if (clickedButton == myJButton)
{
JOptionPane.showMessageDialog(null, "mamama!");
}
}
public static void main(String[] args)
{
GuiImageButtonSample guiTemp = new GuiImageButtonSample();
guiTemp.setVisible(true);
}
} // End of Class