Download here

Transcript
* Returns balloon location.
* @return vertical location
*/
public int getY() { return yCoord; }
}
8. The class BalloonView – the View.
import java.awt.*;
/**
* A view of the Balloon in an imaginable world (playground)
* Implemented as blue canvas (Panel) with red circle
* representing the balloon
*
* @author Eugene Ageenko
* @version 0.1 (Apr 9, 2003)
*/
public class BalloonView extends Canvas {
private Dimension preferredSize;
// reference to the balloon model
protected BalloonModel balloon;
/** A constructor for the view
* @param b reference to the Balloon
*/
public BalloonView (BalloonModel b) {
this.balloon = b;
}
/**
* Sets preferred size for the view.
* @param d preferred size referenced as Dimension object.
*/
public void setPreferredSize(Dimension d) {
if (preferredSize == null)
preferredSize = new Dimension(d);
else
preferredSize.setSize(d);
}
/**
* Returns preferred size for the view. Use by layout manager.
* @return preferred size referenced as Dimension object.
*/
public Dimension getPreferredSize() { return preferredSize; }
/**
* Move balloon to the center of the playground.
*/
public void centerBalloon() {
Dimension dim = getSize();
balloon.setLocation(dim.width/2, dim.height/2);
26