1 36 37 40 41 package java2d.demos.Composite; 42 43 import java.awt.*; 44 import java.awt.geom.Ellipse2D ; 45 import java.awt.geom.Rectangle2D ; 46 import java.awt.geom.RoundRectangle2D ; 47 import java.awt.font.TextLayout ; 48 import java.awt.font.FontRenderContext ; 49 import java2d.Surface; 50 51 import static java.awt.Color .*; 52 53 56 public class ACimages extends Surface { 57 58 private static String s[] = { "box", "fight", "magnify", 59 "boxwave", "globe", "snooze", 60 "tip", "thumbsup", "dukeplug"}; 61 private static Image imgs[] = new Image[s.length]; 62 private static Color colors[] = { BLUE, CYAN, GREEN, 63 MAGENTA, ORANGE, PINK, RED, YELLOW, LIGHT_GRAY }; 64 65 66 public ACimages() { 67 setBackground(WHITE); 68 for (int i = 0; i < imgs.length; i++) { 69 imgs[i] = getImage(s[i] + ".gif"); 70 } 71 } 72 73 74 public void render(int w, int h, Graphics2D g2) { 75 76 float alpha = 0.0f; 77 int iw = w/3; 78 int ih = (h-45)/3; 79 float xx = 0, yy = 15; 80 81 for (int i =0; i < imgs.length; i++) { 82 83 xx = (i%3 == 0) ? 0 : xx+w/3; 84 switch (i) { 85 case 3 : yy = h/3+15; break; 86 case 6 : yy = h/3*2+15; 87 } 88 89 g2.setComposite(AlphaComposite.SrcOver); 90 g2.setColor(BLACK); 91 AlphaComposite ac = AlphaComposite.SrcOver.derive(alpha += .1f); 92 String s = "a=" + Float.toString(alpha).substring(0,3); 93 new TextLayout (s,g2.getFont(), g2.getFontRenderContext()).draw(g2, xx+3, yy-2); 94 95 Shape shape=null; 96 97 switch (i%3) { 98 case 0 : shape = new Ellipse2D.Float (xx, yy, iw, ih); 99 break; 100 case 1 : shape = new RoundRectangle2D.Float (xx, yy, iw, ih, 25, 25); 101 break; 102 case 2 : shape = new Rectangle2D.Float (xx, yy, iw, ih); 103 break; 104 } 105 g2.setColor(colors[i]); 106 g2.setComposite(ac); 107 g2.fill(shape); 108 g2.drawImage(imgs[i], (int) xx, (int) yy, iw, ih, null); 109 } 110 } 111 112 113 public static void main(String s[]) { 114 createDemoFrame(new ACimages()); 115 } 116 } 117 | Popular Tags |