001    package breakout;
002    
003    import java.awt.*;
004    
005    /** Pretty much as basic a BreakoutComponent as you can get.
006      * Okay, so it's green, and it does have a default size, but other than that, basic basic.
007    **/
008    public class BasicBreakoutComponent implements BreakoutComponent {
009            /** The size of this BasicBreakoutComponent. **/
010            protected Dimension size;
011            /** The location of this BasicBreakoutComponent. **/
012            protected Point location;
013            
014            /** Creates a BasicBreakoutComonent of default size(60x20). **/
015            public BasicBreakoutComponent() {
016                    this(new Dimension(60,20));
017            }
018            /** Creates a BasicBreakoutComponent of specified size. 
019              *
020              * @param newSize a Dimension object representing the intended size of the BasicBreakoutComponent. 
021            **/
022            public BasicBreakoutComponent(Dimension newSize) {
023                    this.size = new Dimension(newSize.width, newSize.height);
024            }
025            
026            /** Sets the location of this BasicBreakoutComponent.
027              * @param p a Point Object representing the intended location of the BasicBreakoutComponent.
028            **/
029            public void setLocation(Point p) {
030                    this.location = new Point(p.x, p.y);
031            }
032            /** Gets the location of this BasicBreakoutComponent.
033              * @return A new Point object representing this BasicBreakoutComponent's current location.
034            **/
035            public Point getLocation() {
036                    return new Point(this.location.x, this.location.y);
037            }
038            /** Gets the size of this BasicBreakoutComponent.
039              * @return A new Dimension object representing this BasicBreakoutComponent's size.
040            **/
041            public Dimension getSize() {
042                    return new Dimension(this.size.width, this.size.height);
043            }
044            
045            /** Called by World every tick; empty method. **/
046            public void update() {}
047            
048            /** Called by a Rebounding BreakoutComponent when it has detected an intersection with
049              * this BasicBreakoutComponent.
050              * @param bc the BreakoutComponent/Rebounding object that detected the intersection.
051              * @return <code>false</code> by default -- doesn't die when hit.
052            **/
053            public boolean hit(BreakoutComponent bc) { return false; }
054            
055            /** Gets the java.awt.Shape of this BasicBreakoutComponent.
056              * @return a new Shape label at the same location and of the same size/shape as this BasicBreakoutComponent.
057            **/
058            public Shape getShape() {
059                return new Rectangle(this.location, this.size);
060            }
061            
062            /** Paints the BasicBreakoutComponent.
063              * It happens to be green, and rectangular.  So there.
064              * @param g Graphics object of this BasicBreakoutComponent's coordinate frame
065              *  (ie, already located where we are).
066            **/
067            public void paint(Graphics g) {
068                    g.setColor(Color.green);
069                    g.fillRect(0,0,this.size.width, this.size.height);
070            }
071    }