import java.awt.*;

public class AtmoDemo extends java.applet.Applet  {

  Image plnimg ;
  Point locate ;
  double alt ;

  public void init() {
     setBackground(Color.white) ;
     plnimg = getImage(getCodeBase(),
      "images/plane.gif");
     locate = new Point(100,300) ;
     alt = 0.0 ;
  }
  
  public boolean mouseUp(Event evt, int x, int y) {
     handle(x,y) ;
     return true;
  }

  public boolean mouseDrag(Event evt, int x, int y) {
     handle(x,y) ;
     return true;
  }

  public void handle(int x, int y) {
     locate = new Point(x,y) ;
     if (locate.y > 300) locate.y = 300 ;
     if (locate.y < 50) locate.y = 50 ;
     alt = 200. * (300 - locate.y) ;
     repaint() ;
  }

  public void update(Graphics g) {
     g.clipRect(125, 25, 240, 350) ;
     paint(g) ;
  }

  public void paint(Graphics g) {
      int iwidth = plnimg.getWidth(this) ;
      int iheight = plnimg.getHeight(this) ;
      Font f = new Font("Helvetica",Font.PLAIN,18);
      g.setFont(f) ;
        // Instructions
      g.drawString("Move Airplane to Desired Altitude",10,15);
        // Airplane on Background
      g.setColor(Color.blue) ;
      g.fillRect(0,20,250,310) ;
      g.drawImage(plnimg,120,locate.y-20,iwidth,iheight,this) ;
        // Axis
      g.setColor(Color.white) ; 
      g.drawString("Altitude (feet)",10,40);
      g.drawString("50,000",10,60);
      g.drawString("40,000",10,105);
      g.drawString("30,000",10,155);
      g.drawString("20,000",10,205);
      g.drawString("10,000",10,255);
      g.drawString("0",10,300);

      g.drawLine(100,50,100,300) ;
      g.drawLine(102,50,102,300) ;

      g.drawLine(90,300,110,300) ;
      g.drawLine(90,250,110,250) ;
      g.drawLine(90,200,110,200) ;
      g.drawLine(90,150,110,150) ;
      g.drawLine(90,100,110,100) ;
      g.drawLine(90,50,110,50) ;

      g.fillRect(125,330,250,350) ;
      g.setColor(Color.black) ; 
      g.drawString("Altitude = ",20,350);
      g.drawString(Double.toString(alt),125,350);
      g.drawString("feet",200,350);
  }
}