/** * Create a new die image, that displays a given value on its face and is positioned at (0,0) * * @param value the value to be displayed on the die face */ public GDieImage(int value) { // must invoke super constructor first, so create a temporary 1x1 image, we will reset it // momentarily super(new int[1][1]); if (!isDiceImageLoaded) { // get the image of all die faces from the dice.png resource, and store in a static variable // update isDiceImageLoaded accordingly diceGImage = new GImage(new int[1][1]); InputStream diceInputStream = this.getClass().getResourceAsStream("dice.png"); try { Image diceImage = ImageIO.read(diceInputStream); diceGImage.setImage(diceImage); isDiceImageLoaded = true; } catch (IOException e) { System.out.println("There was a problem loading the dice image"); } } // display the right die-face picture for this value displayValue(value); }