import java.awt.*;import Planet;import Rocket;public class GraphPanel extends Panel{	public double minY;	public double maxY;	public double minX;	public double maxX;	public double xScale;		protected double values[];		// array of values to plot	protected Rectangle graphRect;	public void init() {		graphRect = new Rectangle();		graphRect.resize(0,0);		xScale = 1;	}		public void resize(Dimension d) { resize(d.width, d.height); }		public void resize(int width, int height) {		// here, we'll just set graphRect's width to 0		// to signify that we need to recalculate it later!		graphRect.resize(0,0);	}		protected double calcBoundUp( double x ) { return calcBound(x,1); }	protected double calcBoundDown( double x) { return calcBound(x,-1); }	protected double calcBound( double x, int sign ) {		// this function takes a number x, and calculates a nice "round" number		// greater than x for use as an upper bound on the Y-axis.		if (x == 0) return 0;		double round5 = Math.pow(5, (int)(Math.log(x) / Math.log(5) - 1) );		return ( (int)(x / round5) + sign) * round5;	}	public void setData( double data[] ) {		values = data;		minX = 0;		maxX = data.length - 1;		minY = data[0];		maxY = data[0];		for (int i=0; i<maxX; i++) {			if (data[i] < minY) minY = data[i];			if (data[i] > maxY) maxY = data[i];		}		// now we have max and min, round them to nice even numbers		minY = calcBoundDown( minY );		maxY = calcBoundUp( maxY );	}		protected void setGraphRect() {		graphRect = getGraphics().getClipRect();		graphRect.x += 40;		graphRect.y += 4;		graphRect.width -= 44;		graphRect.height -= 24;	}		protected int valToScreenX(double x) {		return (int)(graphRect.x + (x-minX)/(maxX-minX) * graphRect.width);	}		protected int valToScreenY(double y) {		return (int)(graphRect.y + graphRect.height -				 (y-minY)/(maxY-minY) * graphRect.height);	}		public void paint( Graphics g ) {		if (graphRect.width < 1) setGraphRect();		g.setColor( Color.black );		g.drawRect( graphRect.x-1, graphRect.y-1, graphRect.width+2, graphRect.height+2 );		g.setColor( Color.white );		g.fillRect( graphRect.x, graphRect.y, graphRect.width, graphRect.height );		g.setColor( Color.red );		for (int i=0; i<values.length-1; i++) {			g.drawLine( valToScreenX(i), valToScreenY(values[i]),						valToScreenX(i+1), valToScreenY(values[i+1]) );		}				g.setColor( Color.black );		g.drawString( ""+maxY, 2, graphRect.y + 12 );		g.drawString( ""+minY, 2, graphRect.y + graphRect.height );		g.drawString( ""+minX, graphRect.x, graphRect.y + graphRect.height + 16 );		g.drawString( ""+maxX*xScale, graphRect.x + graphRect.width - 20, 						graphRect.y + graphRect.height + 16 );				}}