Since, you have mentioned that you have tried to do lot of changes in your coding, I am sure that you are having sample of it. It would be easy for us to explain you according to your coding.
I am sorry, for not providing the coding. I have the following code, but I want the image covers only the halves of my JFrame .. what should I change it to fit as I want?
Code:
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
Import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
(public class ImageTest
public static void main (String [] args) (
ImagePanel panel = new ImagePanel (new ImageIcon ("images / background.png"). GetImage ());
JFrame frame = new JFrame ();
frame.getContentPane (). add (panel);
frame.pack ();
frame.setVisible (true);
)
)
ImagePanel class extends JPanel (
private Image img;
Public ImagePanel (String img) (
this (new ImageIcon (img). getImage ());
)
Public ImagePanel (Image img) (
this.img = img;
Dimension size = new Dimension (img.getWidth (null), img.getHeight (null));
setPreferredSize (size);
setMinimumSize (size);
setMaximumSize (size);
setSize (size);
setLayout (null);
)
public void paintComponent (Graphics g) (
g.drawImage (img, 0, 0, null);
)
)
Please help me as soon as possible.
Bookmarks