JPanel-এ background ছবি add করা


Example:
<pre>
/**
*
* @author Farsim,Department of CSE, Shahjalal University of Science and Technology
*/
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

class ImagePanel 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(new FlowLayout());
}

public void paintComponent(Graphics g) {
g.drawImage(img, 0, 0, null);
}

}
</pre>

Continue reading

Advertisements