Image Button in Java

Download
Download is available until [expire_date]
  • Version
  • Download 23
  • File Size 605.53 KB
  • File Count 1
  • Create Date April 17, 2016
  • Last Updated April 17, 2016

Image Button in Java

Image Button in Java

This is a gui program in java that demonstrate how to add image to a button.

Note: the image and the java file must be on the same directory.

Source code:

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

public class InsertImage extends JFrame{
private	ImageIcon img1;
private	JButton jb1;
	
InsertImage()
	{
	img1 = new  ImageIcon(getClass().getResource("Tulips.jpg"));
	jb1= new JButton(img1);
	add(jb1);
	}	
	
	public static void main (String args[])	
		{
		InsertImage mygui = new InsertImage();
		mygui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		mygui.setVisible(true);
		mygui.setSize(200 , 200);
	
		}
	
}
, , , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.