/*File: DiceCanvasGIF.java */ /* Draws from 1 to 12 dice on a canvas */ import java.awt.*; import java.net.*; //import java.applet.*; //import java.awt.image.*; class DiceCanvasGIF extends Canvas { int dieValue[]; //array of dice values int ndice; //number of dice Font f = new Font("TimesRoman", Font.BOLD,48); int sumX; // sum of x values for display DiceGIF applet; Image[] dieGIF = new Image[6]; int imageWidth , imageHeight; Graphics offscreenGraphics; Image offscreenImage; public DiceCanvasGIF(int[] dieValue, int ndice,DiceGIF applet, Image[] dieGIF){ this.applet=applet; this.ndice=ndice; this.dieValue = dieValue; this.dieGIF = dieGIF; } public void clearCanvas(int ndice){ this.ndice=ndice; this.dieValue = new int[ndice]; repaint(); } // public void pleaseWait(applet){ public void paint(Graphics g){ Dimension r=size(); int downshift; // if i >2, put dice in lower half of canvas int rightshift; //number of positions to shift over for (int i=0;(i <12 & i< ndice);i++) { downshift = (i/4)*r.height/3; rightshift= (i%4)*r.width/4; System.out.println("dieValue[i]="+dieValue[i]+i); if(dieValue[i] != 0){ g.drawImage(dieGIF[dieValue[i]-1],7+rightshift,5+downshift,Color.black,applet);} } g.setFont(f); g.setColor( Color.black); String s="X = "+ sumX; g.drawString(s,r.width/4,r.height*4/5); } public void update(int[] dieValue, int sumX) { this.dieValue = dieValue; this.sumX= sumX; repaint(); } }