package interactiveproject.bankaccount;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Ronny
 */
public class bankNotePanel extends javax.swing.JPanel {

    private BufferedImage image;
    private int notes = 0;

    public bankNotePanel() {
        initComponents();
    }

    public void setNotes(int notes) {
        this.notes = notes;
        this.repaint();
    }

    public void drawNumberOfNotes(Graphics g) {
        g.setColor(Color.BLACK);
        String winString = String.valueOf(notes);
        Font font = new Font("TimesRoman", Font.BOLD, 24);
        g.setFont(font);
        FontMetrics metrics = g.getFontMetrics();

        // Determine the X coordinate for the text
        int x = 0 + (getWidth() - metrics.stringWidth(winString)) / 2;
        // Determine the Y coordinate for the text (note we add the ascent, as in java 2d 0 is top of the screen)
        int y = 0 + ((getHeight() - metrics.getHeight()) / 2) + metrics.getAscent();
        // Set the font

        // Draw the String
        g.drawString(winString, x, y);
    }

    public void setImage(String imageName) {
        try {
            image = ImageIO.read(getClass().getResourceAsStream("/interactiveproject/bankaccount/" + imageName + ".jpg"));
        } catch (IOException ex) {
            Logger.getLogger(bankNotePanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void paintComponent(Graphics g) {
        if (image != null) {
            g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
        }
        drawNumberOfNotes(g);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
