CODEFETCH™
            Examples
Searched for 4 expression(s): game   scale   image   buffer  
Java API
java.awt.image.BufferedImage search codefetch
The BufferedImage subclass describes an Image with an accessible buffer of image data.
java.awt.image.BufferedImageFilter search codefetch
The BufferedImageFilter class subclasses an ImageFilter to provide a simple means of using a single-source/single-destination...
java.awt.image.AreaAveragingScaleFilter search codefetch
An ImageFilter class for scaling images using a simple area averaging algorithm that produces smoother results than the neare...
java.awt.image.BufferStrategy search codefetch
The BufferStrategy class represents the mechanism with which to organize complex memory on a particular Canvas or Window.
java.awt.image.DataBuffer search codefetch
This class exists to wrap one or more data arrays.
javax.imageio.ImageTypeSpecifier.createBufferedImage search codefetch
javax.imageio.ImageTypeSpecifier.createFromBufferedImageType search codefetch
Returns an ImageTypeSpecifier that encodes one of the standard BufferedImage types (other than TYPE_CUSTOM ).
java.awt.image.BufferedImageFilter.getBufferedImageOp search codefetch
Returns the BufferedImageOp.
javax.imageio.ImageTypeSpecifier.getBufferedImageType search codefetch
Returns an int containing one of the enumerated constant values describing image formats from BufferedImage.
javax.imageio.ImageTypeSpecifier.createFromRenderedImage search codefetch
Returns an ImageTypeSpecifier that encodes the layout of a RenderedImage (which may be a BufferedImage ).
Most relevant API matches shown. View All.
Source code below from:
Killer Game Programming in Java
By Andrew Davison
Published 20 May, 2005
Average rating

      Powells     Alibris

KGPJ Code/.BAH7503 4/ImagesTests/ImagesTests.java (705 lines)
1  
2 // ImagesTests.java
3 // Andrew Davison, April 2005, ad@fivedots.coe.psu.ac.th 
4  
5 /* Display a screen-full of images, exhibiting various animated
6    effects. 
7  
8    The images are loaded with the ImagesLoader object, so are 
9    defined as 'o', 'n', 's' and 'g' images.
10  
11    The single images (the 'o' images)
12    can have various special effects applied to them. This is done 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
18 19 * resizingImage(): the image grows; 20 * flippingImage(): keep flipping the image horizontally and vertically; 21 * fadingImage(): the image smoothly fades away to nothing; 22 * rotatingImage(): spin the image in a clockwise direction; 23 * blurringImage(): make the image increasingly more blurred; 24 * reddenImage(): turn the image ever more red; 25 * brighteningImage(): keep turning up the image's brightness; 26 * negatingImage(): keep switching betwen the image and its negative; 27 * mixedImage(); keep mixing up the colours of the image; 28 * teleportImage(): make the image fade, pixels at a time; 29 * zapImage(): change the image to a mass of yellow and red pixels; 30 31 ------ 32 The 'n', 's', and 'g' images are animated by 33 showing their component images one after another, in a cycle. 34 The 'n' and 's' images use ImagesPlayer objects to do this. 35
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39 A Swing Timer is used to trigger the 40 updates and redraws of the images every PERIOD ms. 41 42 The 'cats', 'kaboom', 'cars', and 'fighter' images come from 43 the SpriteLib sprite library of images by Ari Feldman at 44 http://www.arifeldman.com/games/spritelib.html 45 46 The basn6a08.png and basn6a16.png images come from the PNG Suite 47 of Willem van Schaik at http://www.schaik.com/pngsuite/pngsuite.html
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51 import java.awt.event.*; 52 import java.awt.image.*; 53 import javax.swing.*; 54 import javax.imageio.*; 55 import java.io.*;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
58 59 public class ImagesTests extends JPanel 60 implements ActionListener, 61 ImagesPlayerWatcher 62 { 63 private final static String IMS_FILE = "imsInfo.txt"; 64 /* The file holding the 'o', 'n', 's', and 'g' image information, 65 extracted with an ImagesLoader object. */ 66
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68 /* A Swing timer is triggered every PERIOD ms to update 69 and redraw the images. */ 70
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
74 75 private ImagesLoader imsLoader; // the image loader 76 private int counter; 77 private boolean justStarted; 78 private ImageSFXs imageSfx; // the special effects class 79
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83 84 // hold the single 'o' images 85 private BufferedImage atomic, balls, bee, cheese, eyeChart, 86 house, pumpkin, scooter,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
88 89 // for manipulating the 'n' and 's' images 90 private ImagesPlayer numbersPlayer, figurePlayer, carsPlayer, 91 catsPlayer, kaboomPlayer; 92 93 // temporary BufferedImages used for the 'teleport' and 'zapping' effects 94 private BufferedImage teleImage = null; 95 private BufferedImage zapImage = null; 96 97 98 public ImagesTests() 99 {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
111 112 // load and initialise the images 113 imsLoader = new ImagesLoader(IMS_FILE); 114 imageSfx = new ImageSFXs(); 115 initImages(); 116
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
120 new Timer(PERIOD, this).start(); // start the Swing timer 121 } // end of ImagesTests() 122 123 124 private void initImages() 125 { 126 // initialize the 'o' image variables 127 atomic = imsLoader.getImage("atomic"); 128 balls = imsLoader.getImage("balls"); 129 bee = imsLoader.getImage("bee"); 130 cheese = imsLoader.getImage("cheese"); 131 eyeChart = imsLoader.getImage("eyeChart"); 132 house = imsLoader.getImage("house"); 133 pumpkin = imsLoader.getImage("pumpkin"); 134 scooter = imsLoader.getImage("scooter"); 135 ufo = imsLoader.getImage("ufo"); 136 owl = imsLoader.getImage("owl"); 137 basn8 = imsLoader.getImage("basn6a08"); 138 basn16 = imsLoader.getImage("basn6a16"); 139 140 /* Initialize ImagesPlayers for the 'n' and 's' images. 141 The 'numbers' sequence is not cycled, the other are.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
143 numbersPlayer = 144 new ImagesPlayer("numbers", PERIOD, 1, false, imsLoader); 145 numbersPlayer.setWatcher(this); // report the sequence's end back here
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
147 figurePlayer = 148 new ImagesPlayer("figure", PERIOD, 2, true, imsLoader); 149 carsPlayer = 150 new ImagesPlayer("cars", PERIOD, 1, true, imsLoader); 151 catsPlayer = 152 new ImagesPlayer("cats", PERIOD, 0.5, true, imsLoader); 153 kaboomPlayer = 154 new ImagesPlayer("kaboom", PERIOD, 1.5, true, imsLoader); 155 156 // the 'g' image, the fighter is set using a filename prefix 157 fighter = imsLoader.getImage("fighter", "left"); 158 } // end of initImages() 159 160 161 public void sequenceEnded(String imageName) 162 // called by ImagesPlayer when its images sequence has finished 163 { System.out.println( imageName + " sequence has ended"); } 164
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
172 else 173 imagesUpdate(); 174
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
179 180 private void imagesUpdate() 181 { 182 // numbered images ('n' images); using ImagesPlayer 183 numbersPlayer.updateTick(); 184 if (counter%30 == 0) // restart the image sequence periodically 185 numbersPlayer.restartAt(2);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
188 189 // strip images ('s' images); using ImagesPlayer 190 carsPlayer.updateTick();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
193 194 // grouped images ('g' images) 195 // The 'fighter' images are the only grouped images in this example. 196 updateFighter(); 197 } // end of imagesUpdate() 198
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
201 private void updateFighter() 202 /* The info in Images/imsInfo.txt for 'fighter' is: 203 g fighter left.gif right.gif still.gif up.gif
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
207 208 The images are shown using their filename prefixes (although a 209 positional approach could be used, which would allow an 210 ImagesPlayer to be employed. 211 */ 212 { 213 int posn = counter % 4; // number of fighter images; 214 // could use imsLoader.numImages("fighter") 215 switch(posn) { 216 case 0: 217 fighter = imsLoader.getImage("fighter", "left"); 218 break; 219 case 1: 220 fighter = imsLoader.getImage("fighter", "right"); 221 break; 222 case 2: 223 fighter = imsLoader.getImage("fighter", "still"); 224 break; 225 case 3: 226 fighter = imsLoader.getImage("fighter", "up"); 227 break;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
229 System.out.println("Unknown fighter group name"); 230 fighter = imsLoader.getImage("fighter", "left"); 231 break;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
237 public void paintComponent(Graphics g) 238 /* The special effects are applied to the single images 239 inside paintComponent(). 240 241 The single images are: 242 * atomic : a GIF of an atom
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
267 268 // smoother (and slower) image transformations (e.g. for resizing) 269 g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
275 276 // display current images 277 // ------------------ single 'o' images --------------------- 278 279 /* The programmer must manualy edit the code here in order to 280 draw the 'o' images with different special effects. */ 281 282 // drawImage(g2d, atomic, 10, 25); 283 rotatingImage(g2d, atomic, 10, 25);

KGPJ Code/.BAH7576 4/ImagesTests/ImagesTests.java (705 lines)
1  
2 // ImagesTests.java
3 // Andrew Davison, April 2005, ad@fivedots.coe.psu.ac.th 
4  
5 /* Display a screen-full of images, exhibiting various animated
6    effects. 
7  
8    The images are loaded with the ImagesLoader object, so are 
9    defined as 'o', 'n', 's' and 'g' images.
10  
11    The single images (the 'o' images)
12    can have various special effects applied to them. This is done 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
18 19 * resizingImage(): the image grows; 20 * flippingImage(): keep flipping the image horizontally and vertically; 21 * fadingImage(): the image smoothly fades away to nothing; 22 * rotatingImage(): spin the image in a clockwise direction; 23 * blurringImage(): make the image increasingly more blurred; 24 * reddenImage(): turn the image ever more red; 25 * brighteningImage(): keep turning up the image's brightness; 26 * negatingImage(): keep switching betwen the image and its negative; 27 * mixedImage(); keep mixing up the colours of the image; 28 * teleportImage(): make the image fade, pixels at a time; 29 * zapImage(): change the image to a mass of yellow and red pixels; 30 31 ------ 32 The 'n', 's', and 'g' images are animated by 33 showing their component images one after another, in a cycle. 34 The 'n' and 's' images use ImagesPlayer objects to do this. 35
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39 A Swing Timer is used to trigger the 40 updates and redraws of the images every PERIOD ms. 41 42 The 'cats', 'kaboom', 'cars', and 'fighter' images come from 43 the SpriteLib sprite library of images by Ari Feldman at 44 http://www.arifeldman.com/games/spritelib.html 45 46 The basn6a08.png and basn6a16.png images come from the PNG Suite 47 of Willem van Schaik at http://www.schaik.com/pngsuite/pngsuite.html
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51 import java.awt.event.*; 52 import java.awt.image.*; 53 import javax.swing.*; 54 import javax.imageio.*; 55 import java.io.*;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
58 59 public class ImagesTests extends JPanel 60 implements ActionListener, 61 ImagesPlayerWatcher 62 { 63 private final static String IMS_FILE = "imsInfo.txt"; 64 /* The file holding the 'o', 'n', 's', and 'g' image information, 65 extracted with an ImagesLoader object. */ 66
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68 /* A Swing timer is triggered every PERIOD ms to update 69 and redraw the images. */ 70
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
74 75 private ImagesLoader imsLoader; // the image loader 76 private int counter; 77 private boolean justStarted; 78 private ImageSFXs imageSfx; // the special effects class 79
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83 84 // hold the single 'o' images 85 private BufferedImage atomic, balls, bee, cheese, eyeChart, 86 house, pumpkin, scooter,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
88 89 // for manipulating the 'n' and 's' images 90 private ImagesPlayer numbersPlayer, figurePlayer, carsPlayer, 91 catsPlayer, kaboomPlayer; 92 93 // temporary BufferedImages used for the 'teleport' and 'zapping' effects 94 private BufferedImage teleImage = null; 95 private BufferedImage zapImage = null; 96 97 98 public ImagesTests() 99 {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
111 112 // load and initialise the images 113 imsLoader = new ImagesLoader(IMS_FILE); 114 imageSfx = new ImageSFXs(); 115 initImages(); 116
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
120 new Timer(PERIOD, this).start(); // start the Swing timer 121 } // end of ImagesTests() 122 123 124 private void initImages() 125 { 126 // initialize the 'o' image variables 127 atomic = imsLoader.getImage("atomic"); 128 balls = imsLoader.getImage("balls"); 129 bee = imsLoader.getImage("bee"); 130 cheese = imsLoader.getImage("cheese"); 131 eyeChart = imsLoader.getImage("eyeChart"); 132 house = imsLoader.getImage("house"); 133 pumpkin = imsLoader.getImage("pumpkin"); 134 scooter = imsLoader.getImage("scooter"); 135 ufo = imsLoader.getImage("ufo"); 136 owl = imsLoader.getImage("owl"); 137 basn8 = imsLoader.getImage("basn6a08"); 138 basn16 = imsLoader.getImage("basn6a16"); 139 140 /* Initialize ImagesPlayers for the 'n' and 's' images. 141 The 'numbers' sequence is not cycled, the other are.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
143 numbersPlayer = 144 new ImagesPlayer("numbers", PERIOD, 1, false, imsLoader); 145 numbersPlayer.setWatcher(this); // report the sequence's end back here
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
147 figurePlayer = 148 new ImagesPlayer("figure", PERIOD, 2, true, imsLoader); 149 carsPlayer = 150 new ImagesPlayer("cars", PERIOD, 1, true, imsLoader); 151 catsPlayer = 152 new ImagesPlayer("cats", PERIOD, 0.5, true, imsLoader); 153 kaboomPlayer = 154 new ImagesPlayer("kaboom", PERIOD, 1.5, true, imsLoader); 155 156 // the 'g' image, the fighter is set using a filename prefix 157 fighter = imsLoader.getImage("fighter", "left"); 158 } // end of initImages() 159 160 161 public void sequenceEnded(String imageName) 162 // called by ImagesPlayer when its images sequence has finished 163 { System.out.println( imageName + " sequence has ended"); } 164
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
172 else 173 imagesUpdate(); 174
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
179 180 private void imagesUpdate() 181 { 182 // numbered images ('n' images); using ImagesPlayer 183 numbersPlayer.updateTick(); 184 if (counter%30 == 0) // restart the image sequence periodically 185 numbersPlayer.restartAt(2);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
188 189 // strip images ('s' images); using ImagesPlayer 190 carsPlayer.updateTick();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
193 194 // grouped images ('g' images) 195 // The 'fighter' images are the only grouped images in this example. 196 updateFighter(); 197 } // end of imagesUpdate() 198
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
201 private void updateFighter() 202 /* The info in Images/imsInfo.txt for 'fighter' is: 203 g fighter left.gif right.gif still.gif up.gif
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
207 208 The images are shown using their filename prefixes (although a 209 positional approach could be used, which would allow an 210 ImagesPlayer to be employed. 211 */ 212 { 213 int posn = counter % 4; // number of fighter images; 214 // could use imsLoader.numImages("fighter") 215 switch(posn) { 216 case 0: 217 fighter = imsLoader.getImage("fighter", "left"); 218 break; 219 case 1: 220 fighter = imsLoader.getImage("fighter", "right"); 221 break; 222 case 2: 223 fighter = imsLoader.getImage("fighter", "still"); 224 break; 225 case 3: 226 fighter = imsLoader.getImage("fighter", "up"); 227 break;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
229 System.out.println("Unknown fighter group name"); 230 fighter = imsLoader.getImage("fighter", "left"); 231 break;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
237 public void paintComponent(Graphics g) 238 /* The special effects are applied to the single images 239 inside paintComponent(). 240 241 The single images are: 242 * atomic : a GIF of an atom
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
267 268 // smoother (and slower) image transformations (e.g. for resizing) 269 g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
275 276 // display current images 277 // ------------------ single 'o' images --------------------- 278 279 /* The programmer must manualy edit the code here in order to 280 draw the 'o' images with different special effects. */ 281 282 // drawImage(g2d, atomic, 10, 25); 283 rotatingImage(g2d, atomic, 10, 25);

KGPJ Code/ImagesTests/ImagesTests.java (705 lines)
1  
2 // ImagesTests.java
3 // Andrew Davison, April 2005, ad@fivedots.coe.psu.ac.th 
4  
5 /* Display a screen-full of images, exhibiting various animated
6    effects. 
7  
8    The images are loaded with the ImagesLoader object, so are 
9    defined as 'o', 'n', 's' and 'g' images.
10  
11    The single images (the 'o' images)
12    can have various special effects applied to them. This is done 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
18 19 * resizingImage(): the image grows; 20 * flippingImage(): keep flipping the image horizontally and vertically; 21 * fadingImage(): the image smoothly fades away to nothing; 22 * rotatingImage(): spin the image in a clockwise direction; 23 * blurringImage(): make the image increasingly more blurred; 24 * reddenImage(): turn the image ever more red; 25 * brighteningImage(): keep turning up the image's brightness; 26 * negatingImage(): keep switching betwen the image and its negative; 27 * mixedImage(); keep mixing up the colours of the image; 28 * teleportImage(): make the image fade, pixels at a time; 29 * zapImage(): change the image to a mass of yellow and red pixels; 30 31 ------ 32 The 'n', 's', and 'g' images are animated by 33 showing their component images one after another, in a cycle. 34 The 'n' and 's' images use ImagesPlayer objects to do this. 35
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39 A Swing Timer is used to trigger the 40 updates and redraws of the images every PERIOD ms. 41 42 The 'cats', 'kaboom', 'cars', and 'fighter' images come from 43 the SpriteLib sprite library of images by Ari Feldman at 44 http://www.arifeldman.com/games/spritelib.html 45 46 The basn6a08.png and basn6a16.png images come from the PNG Suite 47 of Willem van Schaik at http://www.schaik.com/pngsuite/pngsuite.html
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51 import java.awt.event.*; 52 import java.awt.image.*; 53 import javax.swing.*; 54 import javax.imageio.*; 55 import java.io.*;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
58 59 public class ImagesTests extends JPanel 60 implements ActionListener, 61 ImagesPlayerWatcher 62 { 63 private final static String IMS_FILE = "imsInfo.txt"; 64 /* The file holding the 'o', 'n', 's', and 'g' image information, 65 extracted with an ImagesLoader object. */ 66
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68 /* A Swing timer is triggered every PERIOD ms to update 69 and redraw the images. */ 70
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
74 75 private ImagesLoader imsLoader; // the image loader 76 private int counter; 77 private boolean justStarted; 78 private ImageSFXs imageSfx; // the special effects class 79
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83 84 // hold the single 'o' images 85 private BufferedImage atomic, balls, bee, cheese, eyeChart, 86 house, pumpkin, scooter,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
88 89 // for manipulating the 'n' and 's' images 90 private ImagesPlayer numbersPlayer, figurePlayer, carsPlayer, 91 catsPlayer, kaboomPlayer; 92 93 // temporary BufferedImages used for the 'teleport' and 'zapping' effects 94 private BufferedImage teleImage = null; 95 private BufferedImage zapImage = null; 96 97 98 public ImagesTests() 99 {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
111 112 // load and initialise the images 113 imsLoader = new ImagesLoader(IMS_FILE); 114 imageSfx = new ImageSFXs(); 115 initImages(); 116
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
120 new Timer(PERIOD, this).start(); // start the Swing timer 121 } // end of ImagesTests() 122 123 124 private void initImages() 125 { 126 // initialize the 'o' image variables 127 atomic = imsLoader.getImage("atomic"); 128 balls = imsLoader.getImage("balls"); 129 bee = imsLoader.getImage("bee"); 130 cheese = imsLoader.getImage("cheese"); 131 eyeChart = imsLoader.getImage("eyeChart"); 132 house = imsLoader.getImage("house"); 133 pumpkin = imsLoader.getImage("pumpkin"); 134 scooter = imsLoader.getImage("scooter"); 135 ufo = imsLoader.getImage("ufo"); 136 owl = imsLoader.getImage("owl"); 137 basn8 = imsLoader.getImage("basn6a08"); 138 basn16 = imsLoader.getImage("basn6a16"); 139 140 /* Initialize ImagesPlayers for the 'n' and 's' images. 141 The 'numbers' sequence is not cycled, the other are.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
143 numbersPlayer = 144 new ImagesPlayer("numbers", PERIOD, 1, false, imsLoader); 145 numbersPlayer.setWatcher(this); // report the sequence's end back here
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
147 figurePlayer = 148 new ImagesPlayer("figure", PERIOD, 2, true, imsLoader); 149 carsPlayer = 150 new ImagesPlayer("cars", PERIOD, 1, true, imsLoader); 151 catsPlayer = 152 new ImagesPlayer("cats", PERIOD, 0.5, true, imsLoader); 153 kaboomPlayer = 154 new ImagesPlayer("kaboom", PERIOD, 1.5, true, imsLoader); 155 156 // the 'g' image, the fighter is set using a filename prefix 157 fighter = imsLoader.getImage("fighter", "left"); 158 } // end of initImages() 159 160 161 public void sequenceEnded(String imageName) 162 // called by ImagesPlayer when its images sequence has finished 163 { System.out.println( imageName + " sequence has ended"); } 164
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
172 else 173 imagesUpdate(); 174
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
179 180 private void imagesUpdate() 181 { 182 // numbered images ('n' images); using ImagesPlayer 183 numbersPlayer.updateTick(); 184 if (counter%30 == 0) // restart the image sequence periodically 185 numbersPlayer.restartAt(2);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
188 189 // strip images ('s' images); using ImagesPlayer 190 carsPlayer.updateTick();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
193 194 // grouped images ('g' images) 195 // The 'fighter' images are the only grouped images in this example. 196 updateFighter(); 197 } // end of imagesUpdate() 198
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
201 private void updateFighter() 202 /* The info in Images/imsInfo.txt for 'fighter' is: 203 g fighter left.gif right.gif still.gif up.gif
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
207 208 The images are shown using their filename prefixes (although a 209 positional approach could be used, which would allow an 210 ImagesPlayer to be employed. 211 */ 212 { 213 int posn = counter % 4; // number of fighter images; 214 // could use imsLoader.numImages("fighter") 215 switch(posn) { 216 case 0: 217 fighter = imsLoader.getImage("fighter", "left"); 218 break; 219 case 1: 220 fighter = imsLoader.getImage("fighter", "right"); 221 break; 222 case 2: 223 fighter = imsLoader.getImage("fighter", "still"); 224 break; 225 case 3: 226 fighter = imsLoader.getImage("fighter", "up"); 227 break;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
229 System.out.println("Unknown fighter group name"); 230 fighter = imsLoader.getImage("fighter", "left"); 231 break;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
237 public void paintComponent(Graphics g) 238 /* The special effects are applied to the single images 239 inside paintComponent(). 240 241 The single images are: 242 * atomic : a GIF of an atom
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
267 268 // smoother (and slower) image transformations (e.g. for resizing) 269 g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
275 276 // display current images 277 // ------------------ single 'o' images --------------------- 278 279 /* The programmer must manualy edit the code here in order to 280 draw the 'o' images with different special effects. */ 281 282 // drawImage(g2d, atomic, 10, 25); 283 rotatingImage(g2d, atomic, 10, 25);

Not satisfied? Try this search biased towards software and programming:
Google