Source of second Applet


See demo
import java.util.*;
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.awt.event.*;

class Graph {
  final int total = 100;
  int x, y, y2;
  Color LineColor, bkColor;
  Graphics g;

  Graph() {
    LineColor = new Color(8, 8, 8);
    bkColor=new Color(254, 254, 254);
  }
  void setGraphics(Graphics g) {
    this.g=g;
    g.setColor(bkColor);
    g.fillRect(5, 5, 310, 220);
    g.setColor(LineColor);
    g.drawLine(10, 10, 10, 200);
    g.drawLine(10, 200, 300, 200);
  }

  void drawIt(int vals[], Color color) {
    x = y = y2 = 0;
    g.setColor(color);
    for (int var=0; var < total*3; var+=3, x++) {

      y2+=vals[x];
      ThickLine(10+var, 200-y, 13+var, 200-y2, g);
      y=y2;
    }
  }

  public void ThickLine(int x1, int y1, int x2, int y2, Graphics g) {
    g.drawLine(x1, y1, x2, y2);
    g.drawLine(x1+1, y1,x2+1, y2);
  }
}

/* Base class that extends applet */
public class App1 extends Applet {
  final int total=100;
  int m1[]=new int[total];
  int m2[]=new int[total];
  Random r=new Random(65535);
  Graph g1;
	String FontList[];
  Color Blue = new Color(0,255,0);
  Color Green = new Color(0, 0, 255);
  String mousemsg = "";
  int mouseX, mouseY;

  public App1() {
    addMouseListener(new MyMouseAdapter(this) );
  }

  void SetVars(int vars[]) {
    int y=0;
    for (int x=0;x < total;x++) {
      switch((Math.abs(r.nextInt()))%18) {
        case 0: case 1: case 2: case 3: case 15: case 16:
          y=0;
          break;
        case 4: case 5: case 6: case 7: case 17:
          y=1;
          break;
        case 8: case 9: case 10:
          y=2;
          break;
        case 11: case 12:
          y=4;
          break;
        case 13:
          y=3;
          break;
        case 14:
          y=6;
          break;
      }
      vars[x]=y;
    }
  }
  public void init() {
		FontList = getToolkit().getFontList();
    g1 = new Graph();
    setLayout(null);
    resize(400,300);
    Label my = new Label("Comparison", Label.LEFT);
    add(my);
    my.reshape(100, 230, 200, 20);
    showStatus("End of initialization");
  }
  public void start() {
    SetVars(m1);
    SetVars(m2);
    showStatus("Started Ok.");
  }

  public void paint(Graphics g) {

    showStatus("Running.....");

    g1.setGraphics(g);
/*    URL url = getCodeBase();
    String msg = "Code base: " + url.toString();
    g.drawString(msg, 100, 280); */
    g1.drawIt(m1, Color.red);
    g1.drawIt(m2, Color.green);
    g.drawString(mousemsg, 200, 10);
  }
  public void update(Graphics g) {
      paint(g);
  }
}

class MyMouseAdapter extends MouseAdapter {
  App1 appWindow;
  public MyMouseAdapter(App1 appWindow) {
    this.appWindow = appWindow;
  }
  public void mousePressed(MouseEvent me) {
    appWindow.mouseX = me.getX();
    appWindow.mouseY = me.getY();
    appWindow.mousemsg = "Mouse down at " + appWindow.mouseX + ", " + appWindow.mouseY;
    appWindow.repaint();
  }
}