Put image as jframe background

Put image as jframe background


bg.jpg



Source code below will make a jframe with bg.jpg as it's background image.

********************************************************
COMPLETE SOURCE CODE FOR : PutImageOnJFrame.java
********************************************************


import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.FlowLayout;

public class PutImageOnJFrame extends JPanel
{
public PutImageOnJFrame()
{
setOpaque(false);
setLayout(new FlowLayout());
}

public static void main(String[]args)
{
JFrame myFrame=new JFrame("Put Image");
JButton button1=new JButton("Sample 1");
JButton button2=new JButton("Sample 2");
PutImageOnJFrame c=new PutImageOnJFrame();
c.add(button1);
c.add(button2);
myFrame.add(c);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setSize(400,400);
myFrame.setVisible(true);
}

public void paint(Graphics g)
{ //IT DEPEND ON YOUR PICTURE AND PUT IT'S LOCATION IN
Image a=Toolkit.getDefaultToolkit().getImage("E:\\_JAVA_\\---SOURCE CODE---\\bg.jpg");
g.drawImage(a,0,0,getSize().width,getSize().height,this);
super.paint(g);
}

//THANKS FOR WATCHING
}


********************************************************
JUST COMPILE AND EXECUTE IT.
Note : Before that, you must know your image location. Copy and paste your image location into Image a=Toolkit.getDefaultToolkit().getImage(PASTE_IN_THIS);
********************************************************
Related Posts Plugin for WordPress, Blogger...

I Also Can Create T-Shirt Logo For You