// CMPU-101-51, Spring 2007
// Asmt 9 Solutions:  DiePanel.java 

import java.awt.*;
import javax.swing.*;

// The DiePanel class

class DiePanel extends JPanel {

  // ------------------------
  //   class-oriented data
  // ------------------------
  
  // MY_FONT:  the font used to display the die's value onscreen
  static Font MY_FONT = new Font("SansSerif",Font.BOLD,30);
  
  // ------------------------
  //   object-oriented data 
  // ------------------------
  
  // myIndex:  tells which die I am supposed to display
  
  int myIndex = -1;
  
  // yahtz:  the Yahtzee game object.
  //           When I want to display the value of my die,
  //           I ask the Yahtzee object to tell me the
  //           current value.
  Yahtzee yahtz;
  
  // -------------------
  //   constructor
  // -------------------
  
  DiePanel(Yahtzee y, int indy) {
    yahtz = y;
    myIndex = indy;
    
    // set the font for this panel to be the one given above
    this.setFont(MY_FONT);
  }
  
  // -------------------------------
  //   paintComponent
  // -------------------------------
  //  This method gets called AUTOMATICALLY by the operating
  //  system when this panel needs to be repainted.  It also
  //  gets called by the "repaint" method (which we can call
  //  whenever we want the onscreen image to be updated).
  
  public void paintComponent(Graphics g) {
    // set the color of the paintbrush to black
    g.setColor(Color.BLACK);
    // fill the entire panel with the color black
    g.fillRect(0,0,this.getWidth(),this.getHeight());
    // set the color of the paintbrush to white
    g.setColor(Color.WHITE);
    // draw a slightly smaller filled rectangle that is white
    // (all that remains of the black rectangle is a border
    //  that is 2 pixels wide).
    g.fillRect(2,2,this.getWidth()-4,this.getHeight()-4);
    // change the color back to BLACK
    g.setColor(Color.BLACK);
    // draw the numeral representing the current value of
    // the die.  Notice that we ask the Yahtzee object to
    // tell us what the current value of the die is.
    int value = yahtz.getDie(myIndex);
    if (value == -1) g.drawString("-",5,28);
    else g.drawString("" + value,5,28);
      
  }
  
}
