import java.awt.event.*; import javax.swing.*; public class ImageOnJButton implements ActionListener { public static void main(String[] args) { new ImageOnJButton(); } public ImageOnJButton() { JFrame frame = new JFrame("Demo: Image on JButton"); frame.setLayout(null); frame.setSize(250, 240); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setBackground(java.awt.Color.BLACK); ImageIcon pizza = new ImageIcon("data_files/pizza.gif"); JButton button = new JButton(pizza); button.setSize(130, 100); button.setLocation(55, 52); button.setVisible(true); button.addActionListener(this); frame.add(button); frame.setVisible(true); } public void actionPerformed(ActionEvent e) { System.out.println("You pressed the button!"); } }