U:\NetBeans\PokeBall\src\graphicslab04\UltraBall.java
 1 package graphicslab04;
 2
 3 import java.awt.Color;
 4 import java.awt.Graphics;
 5 import java.awt.Graphics2D;
 6 import java.awt.geom.Area;
 7 import java.awt.geom.Ellipse2D;
 8 import java.awt.geom.Rectangle2D;
 9
10 public class UltraBall extends PokeBall {
11
12     private static final Area stripe;
13
14     static {
15         stripe = new Area(PokeBall.topHalf);
16         stripe.subtract(new Area(new Ellipse2D.Double(15, 15, 220, 220)));
17         stripe.add(new Area(new Rectangle2D.Double(25, 0, 35, 250)));
18         stripe.add(new Area(new Rectangle2D.Double(190, 0, 35, 250)));
19         stripe.intersect(new Area(new Rectangle2D.Double(25, 0, 200, 250)));
20         stripe.intersect(PokeBall.topHalf);
21     }
22
23     private final Area myTopHalf;
24     private final Area myStripe;
25
26     public UltraBall(int xp, int yp) {
27         super(xp, yp);
28         myTopHalf = PokeBall.topHalf.createTransformedArea(shift);
29         myStripe = new Area(stripe.createTransformedArea(shift));
30     }
31
32     @Override
33     protected void drawTopHalf(Graphics g) {
34         g.setColor(Color.black);
35         ((Graphics2D) g).fill(myTopHalf);
36         g.setColor(Color.yellow);
37         ((Graphics2D) g).fill(myStripe);
38     }
39 }
40