Java Swing - Create Image Panel
Write Code as below.
public class ImageCheck {
public static void main(String s[])
{
ImagePanel panel = new ImagePanel(new
ImageIcon("aa.jpg").getImage());
JFrame frame = new JFrame("Create Image-" +
"Themed Components");
frame.getContentPane().add(panel);
frame.setVisible(true);
}
}
__________________________________________________________________
Create Image Panel Class:-
First Create a class called ImagePanel.java. Then write the following code in it.
In This Code:
We have used Image as parameter in Constructor of ImagePanel class. This is the image which will set as background Image of JPanel. I have used following Image.
This code will create one customized JPanel class which you can call by instance of this class and it will create a JPanel with an Image as background.
Now We will create another class called ImageCheck.java which call the ImagePanel class and create a JFrame having a Jpanel with above Image.
class ImageTest.java:
Write Code as below.
_______________________________________________________________
import javax.swing.*;public class ImageCheck {
public static void main(String s[])
{
ImagePanel panel = new ImagePanel(new
ImageIcon("aa.jpg").getImage());
JFrame frame = new JFrame("Create Image-" +
"Themed Components");
frame.getContentPane().add(panel);
frame.setVisible(true);
}
}
__________________________________________________________________
Run The Code Code And Get Output like this..
This is the JFrame created with JPanel we created in ImagePanel.java Class with background Image we have used.
Thanks & Enjoy....
Write Comments if you like....
Nirav Raval
Nirav Raval
----------------------------------------------------------------------------------
Follow Other Java Swing Tricks....
No comments:
Post a Comment
Leave Comment If You Like This...Thank You..!