package client.custom;
import java.awt.Graphics;
import java.awt.LayoutManager;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
import client.gfx.wrapper.BGTileImageEngine;
/**
* The <code>JCustomPanel</code> is a subclass of <code>JPanel</code> which adds desired functionality to
* the <code>paintComponent()</code> method of JPanel. Namingly, it uses the <code>BGTileImageEngine</code>
* graphics wrapper to get the desired background of the panel. Used for all the menus present in the GUI, the main background etc.
*
* @author Priidu Neemre
*/
public class JCustomPanel extends JPanel {
private static final long serialVersionUID = 00000001L;
private BGTileImageEngine tileEngine;
private BufferedImage backgroundImage;
public JCustomPanel(String imagePath){
tileEngine = new BGTileImageEngine(imagePath);
}
public JCustomPanel(LayoutManager layout, String imagePath){
super(layout);
tileEngine = new BGTileImageEngine(imagePath);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
backgroundImage = tileEngine.generateTiledBackground(getWidth(), getHeight());
g.drawImage(backgroundImage, 0, 0, null);
}
}