All pastes #2098320 Raw Edit

Dice Class

public text v1 · immutable
#2098320 ·published 2012-01-03 07:22 UTC
rendered paste body
/**
 * NAME: Alex Adusei
 * DATE: Monday, January 2, 2012
 * COURSE CODE: ICS3U1
 * PROGRAM: Dice Class. *Must be run via the DiceGame Class*
 */

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

public class Dice
{
  
  private ImageIcon imgDice;
  private ImageIcon imgDie1;
  private ImageIcon imgDie2;
  private ImageIcon imgDie3;
  private ImageIcon imgDie4;
  private ImageIcon imgDie5;
  private ImageIcon imgDie6;
  
  private ImageIcon img1;
  
  private Random rnd;
  
  public Dice()
  {
    imgDice = new ImageIcon ("C:\\Users\\user\\Desktop\\Dr Java~\\Images\\die0.png");
    imgDie1 = new ImageIcon ("C:\\Users\\user\\Desktop\\Dr Java~\\Images\\die1.png");
    imgDie2 = new ImageIcon ("C:\\Users\\user\\Desktop\\Dr Java~\\Images\\die2.png");
    imgDie3 = new ImageIcon ("C:\\Users\\user\\Desktop\\Dr Java~\\Images\\die3.png");
    imgDie4 = new ImageIcon ("C:\\Users\\user\\Desktop\\Dr Java~\\Images\\die4.png");
    imgDie5 = new ImageIcon ("C:\\Users\\user\\Desktop\\Dr Java~\\Images\\die5.png");
    imgDie6 = new ImageIcon ("C:\\Users\\user\\Desktop\\Dr Java~\\Images\\die6.png");
    img1 = new ImageIcon ("C:\\Users\\user\\Desktop\\Dr Java~\\Images\\die0.png");
    rnd = new Random();
   
  }
  
  public int roll()
  {
    int num1 = rnd.nextInt(6) + 1;
    int num2 = rnd.nextInt(6) + 1;
    
    return num1; 
  }
  
  public int getWidth()
  {
    int width = 105;
    return width;
  }
  
  public int getHeight()
  {
    int height = 107;
    return height;
  }
   
  public Image getDice()
  {
    
    Dice c = new Dice();
    
    if (c.roll() == 1)
    {
      img1 = imgDie1;
    }
    else if (c.roll() == 2)
    {
      img1 = imgDie2;
    }
    else if (c.roll() == 3)
    {
      img1 = imgDie3;
    }
    else if (c.roll() == 4)
    {
      img1 = imgDie4;
    }
    else if (c.roll() == 5)
    {
      img1 = imgDie5;
    }
    else if (c.roll() == 6)
    {
      img1 = imgDie6;
    }
    
    return img1.getImage();
  }
  
}