import edu.neu.ccs.*;
import edu.neu.ccs.gui.*;
import edu.neu.ccs.codec.*;
import edu.neu.ccs.console.*;
import edu.neu.ccs.filter.*;
import edu.neu.ccs.jpf.*;
import edu.neu.ccs.parser.*;
import edu.neu.ccs.pedagogy.*;
import edu.neu.ccs.quick.*;
import edu.neu.ccs.util.*;
import edu.neu.ccs.util.MathUtilities.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.font.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
import java.util.*;
import java.math.*;
import java.beans.*;
import java.lang.reflect.*;
import java.net.URL;
import java.util.regex.*;
import java.text.ParseException;
public class Dice extends DisplayPanel{
private String diceURL = "http://www.ccs.neu.edu/jpt/images/dice/";
private String diceList = "imagelist.txt";
private Tile die1 = null;
private Tile die2 = null;
public static void main(String[] args) {
LookAndFeelTools.adjustAllDefaultFontSizes(3);
new Dice().frame("Random Dice");
}
// show the Dice as Image Paintable Lite
private ImagePaintableLite[] dice =
WebImageTools.readImagesAsPaintableLite
(diceURL, diceList);
private int N = dice.length;
private SimpleAction display = new SimpleAction("Roll Dice") {
public void perform() {showRandomDice();}
};
private void makeTiles() {
die1 = new Tile(dice[0]);
die2 = new Tile(dice[0]);
}
//show Dice if button is clicked
public Dice(){
if (N == 0){
addObject("The Dice failed to load from the web");
return;
}
makeTiles();
makeGUI();
}
//construct the GUI
public void makeGUI() {
int gap = 20;
HTable htable = new HTable(2, gap, gap, CENTER);
htable.addObject(die1, 0, 0);
htable.addObject(die2, 0, 1);
htable.setBackground(Colors.white);
VTable vtable = new VTable(2, gap, gap, CENTER);
vtable.addObject(htable, 0, 0);
vtable.addObject(display, 1, 0);
vtable.matteBorder(3, Color.white);
vtable.matteBorder(5, Color.black);
vtable.matteBorder(7, Color.red);
vtable.matteBorder(12, Color.black);
addObject(vtable);
}
// randomize the Dice
public void showRandomDice() {
int x= MathUtilities.randomInt(1, 6);
die1.setPaintable(dice[x]);
int y= MathUtilities.randomInt(1, 6);
die2.setPaintable(dice[y]);
}
}