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


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

// The ScorePanel class

class ScorePanel extends JPanel {

  
  // ---------------------
  //  class-oriented data 
  // -----------------------
  
  //  MY_FONT:  the font used to display the scores
  static Font MY_FONT = new Font("SansSerif",Font.BOLD,30);

  // ------------------------
  //   object-oriented data
  // ------------------------
  
  // the display color for this panel
  Color color = new Color(220,200,200);
  
  // the Yahtzee object that will tell us the info to display
  Yahtzee yahtz;
  
  // ----------------
  //  constructor
  // ----------------
  
  ScorePanel(Yahtzee y) {
    this.setFont(MY_FONT);
    yahtz = y;
  }
  
  // -----------------------------------------
  //   paintComponent
  // -----------------------------------------
  //   This method is called AUTOMATICALLY by the operating
  //   system whenever this panel needs to be repainted 
  //   onscreen.  
  
  public void paintComponent(Graphics g) {
    // set the foreground color of the paintbrush used by
    //  the graphics object to whatever the display color
    //  is for this panel
    g.setColor(this.color);
    // draw a filled rectangle that covers the entire panel.
    //    NOTE:  The coordinates are relative to the upper
    //           lefthand corner of the panel itself.
    //    Thus, (0,0) specifies the upper-lefthand corner.
    //    The size of the rectangle drawn is 
    //         getWidth() by getHeight().
    g.fillRect(0,0,this.getWidth(),this.getHeight());
    
    // Now, display the score information
    // Notice that we ask the Yahtzee object to tell us
    //  all the information we want to display
    g.setColor(Color.BLACK);
    g.drawString("Cat.  Score", 20, 40);
    for (int i=1; i<=6; i++) {
      g.drawString(""+i, 25, 40+i*35);
      int score = yahtz.getCatScore(i);
      String scr;
      if (score == -1) scr = "_";
      else scr = "" + score;
      g.drawString(scr, 120, 40+i*35);
    }
    g.drawString("Total", 20, 300);
    g.drawString(""+yahtz.computeTotalScore(), 120, 300);
  }
  
  
  
  
  
  
}
