Applet example (Souce)

Here you cannot see blocking because html skippes space or treat them as whitespaces.
Click to have demo.

/*

* Example applet that will show a graph.

*/

import java.util.*;

import java.applet.*;

import java.awt.*;

class Graph {

final int total = 100;

int x, y, y2;

Color c, LineColor, bkColor;

Graph() {

c=new Color(50, 230, 80);

LineColor = new Color(8, 8, 8);

bkColor=new Color(254, 254, 254);

}

void drawIt(Graphics g, int vals[]) {

g.setColor(bkColor);

g.fillRect(5, 5, 310, 220);

g.setColor(LineColor);

g.drawLine(10, 10, 10, 200);

g.drawLine(10, 200, 300, 200);

x = y = y2 = 0;

for (int var=0; var y2+=vals[x];

g.setColor(c);

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);

}

}


class App1 extends Applet {

final int total=100;

int mem[]=new int[total];

Random r;

Graph g1;

void SetMem() {

int y=0;

r = new Random();

for (int x=0;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;

}

mem[x]=y;

}

}

public void init() {

SetMem();

g1 = new Graph();

}

public void paint(Graphics g) {

g1.drawIt(g, mem);

}

public void update(Graphics g) {

paint(g);

}

}