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>CustomMainPanel</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 the background of the startup window, instructions window etc.
*
* @author Priidu Neemre
*/
public class CustomMainPanel extends JPanel{
private static final long serialVersionUID = 00000001L;
private BufferedImage backgroundImage;
private BufferedImage overlayImage;
private BGTileImageEngine tileEBackg;
private BGTileImageEngine tileEOverlay;
public CustomMainPanel(String imagePath, String overlayPath){
tileEBackg = new BGTileImageEngine(imagePath);
tileEOverlay = new BGTileImageEngine(overlayPath);
}
public CustomMainPanel(LayoutManager layout, String imagePath, String overlayPath){
super(layout);
tileEBackg = new BGTileImageEngine(imagePath);
tileEOverlay = new BGTileImageEngine(overlayPath);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
backgroundImage = tileEBackg.generateTiledBackground(getWidth(), getHeight());
overlayImage = tileEOverlay.generateTiledBackground(getWidth(), getHeight());
g.drawImage(backgroundImage, 0, 0, null);
g.drawImage(overlayImage, 0, 0, null);
}
}