Picture Button

//*Made By: Ajinkya Choube*//
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class PictureButton extends JFrame {

public PictureButton( ) {
super(“PictureButton v1.0”);
setSize(200, 200);
setLocation(200, 200);

Icon icon = new ImageIcon(“rhino.gif”);
JButton button = new JButton(icon);
button.addActionListener(new ActionListener( ) {
public void actionPerformed(ActionEvent ae) {

Container content = getContentPane( );
content.setLayout(new FlowLayout( ));

public static void main(String[] args) {
JFrame f = new PictureButton( );
f.addWindowListener(new WindowAdapter( ) {
public void windowClosing(WindowEvent we) { System.exit(0); }

The example creates an ImageIcon from the rhino.gif file. Then a JButton is created from the ImageIcon. The whole thing is displayed in a JFrame. This example also shows the idiom of using an anonymous inner class as an ActionListener.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s