package jimmm.gui;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import jimmm.data.Card;
/**
* Renders a card
* @author Simon Hampe
*
*/
public class CardPanel extends JPanel {
// *** MEMBERS ***
private BufferedImage image;
private Card associatedCard;
// *** CONSTRUCTOR ***
/**
* Displays a card face up
*/
public CardPanel(Card c) {
try {
image = ImageIO.read(new File("graphics/cardset/std/" + c.getColor().toString() + c.getValue().toString() + ".png"));
} catch (IOException e) {
e.printStackTrace();
}
associatedCard = c;
}
// *** GETTER ***
public Card getCard() {
return new Card(associatedCard);
}
// *** OVERRIDDEN METHODS ***
@Override
public void paintComponent(Graphics g) {
// super.paintComponent(g);
g.drawImage(image,0,0,null);
// g.setColor(Color.white);
// g.drawString(associatedCard.getValue().toString(), 5, 10);
// g.drawString(associatedCard.getColor().toString(), 5, 20);
}
//Sets the size of the image as preferred size.
@Override
public Dimension getPreferredSize() {
return new Dimension(image.getWidth(), image.getHeight());
}
}