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

/**
 * Creates a window containing a clickable poker dice
 */
public class DiceWindow 
   extends JFrame              // This class defines a window on the screen
   implements ActionListener   // It also handles button click events
{   
   private ImageIcon[] icons;  
   private Dice theDice;
   private JButton theButton;
   
   public DiceWindow() {
      icons = new ImageIcon[6];
      icons[0] = new ImageIcon("images/Die9-300px.png");
      icons[1] = new ImageIcon("images/Die10-300px.png");
      icons[2] = new ImageIcon("images/DieJack-300px.png");
      icons[3] = new ImageIcon("images/DieQueen-300px.png");
      icons[4] = new ImageIcon("images/DieKing-300px.png");
      icons[5] = new ImageIcon("images/DieAce-300px.png");
      
      theDice = new Dice(6);
      theButton = new JButton(icons[theDice.getValue()-1]);
      theButton.addActionListener(this);
      add(theButton);  
  
      setPreferredSize(new Dimension(350, 350));
      pack();
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setVisible(true);
   }
   
   /**
    * Handles button clicks
    */
   public void actionPerformed(ActionEvent e) { // Called when button clicked
      theDice.roll();
      theButton.setIcon(icons[theDice.getValue()-1]); // Update the icon
   }

   public static void main(String[] arg) throws InterruptedException{
      new DiceWindow();
   }
}