001    // Throbber.java
002    // Created: Wednesday, September 22, 1999 9:54:38 PM
003    
004    package ballworld;
005    
006    import cs101.lang.Animate;
007    
008    /** A ball that sits in place and changes size. This ball can also be moved to
009     * new locations by selecting it and dragging the mouse to the desired new
010     * location.
011     * @author (original author unknown)
012     * @author Patrick G. Heck, gus.heck@olin.edu
013     * @version $Id: Throbber.java,v 1.2 2003/09/11 21:35:37 gus Exp $
014     */
015    public class Throbber implements Ball, Animate {
016    
017            double radius= 5;
018            double radiuschange= 1;
019            
020            double x= 0;
021            double y= 0;
022            
023            World ourWorld;
024            
025            /**
026             * Create a default throbber ball. This ball starts at 0,0.
027             */        
028            public Throbber() { } 
029            
030            /**
031             * Create a throbber at the desired location.
032             *
033             * @param x The starting x position
034             * @param y The starting y position
035             */        
036            public Throbber(double x, double y) {
037                this.x = x;
038                this.y = y;
039            }
040            
041            /** A throbber that starts in the center of the upper right quadrant.
042             * @param w The world in which we are starting
043             */        
044            public Throbber(World w) {
045                this.ourWorld = w;
046                this.x = ourWorld.getMaxX()/2;
047                this.y = ourWorld.getMaxY()/2;
048            }
049            
050            // Contract methods from Ball
051            
052            // inherits doc from Ball        
053            public double getX() {
054                    return x;
055            }
056            
057            // inherits doc from Ball        
058            public double getY() {
059                    return y;
060            }
061            
062            // inherits doc from Ball        
063            public double getRadius() {
064                    return radius; 
065            }
066            
067            // inherits doc from Ball        
068            public void setWorld(World theWorld) {
069            }
070            
071            // inherits doc from Ball        
072            public void userClicked(double x, double y) {
073                    this.x= x;
074                    this.y= y;
075            }
076            
077            // inherits doc from Ball        
078            public void userTyped(char key) {
079                System.out.println("I got a '" + key + "'");
080            }
081    
082    
083            // Contract method from Animate
084            
085            // inherits doc from Animate 
086            public void act() {
087                if (radius>30 || radius<5) {
088                    radiuschange= -radiuschange;
089                }
090                radius+= radiuschange;
091            }
092    }