package client.custom;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JTextField;
import client.gfx.wrapper.BGTileImageEngine;
/**
* The <code>JCustomField</code> is a subclass of <code>JTextField</code> which adds desired functionality to
* the <code>paintComponent()</code> method of JTextField. Namingly, it uses the <code>BGTileImageEngine</code>
* graphics wrapper to get the desired background of the field.
*
* @author Priidu Neemre
*/
public class JCustomField extends JTextField {
private static final long serialVersionUID = 00000001L;
private BGTileImageEngine tileEngine;
private BufferedImage backgroundImage;
public JCustomField(String imagePath) {
tileEngine = new BGTileImageEngine(imagePath);
}
public void paintComponent(Graphics g){
backgroundImage = tileEngine.generateTiledBackground(getWidth(), getHeight());
g.drawImage(backgroundImage, 0, 0, null);
super.paintComponent(g); //Text repainted after the background
}
}