Hola.java



// APPLET QUE RECIBE PARAMETROS PARA DIBUJAR UNA GRAFICA DE BARRA
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Button;



public class Hola extends Applet
{
	int a=0, b=0, c=0, d=0;

	public void init()
	{
		setLayout(null);
                setBackground(Color.yellow);
                setForeground(Color.blue);


		a = Integer.parseInt(getParameter("a"));
		b = Integer.parseInt(getParameter("b"));
		c = Integer.parseInt(getParameter("c"));
		d = Integer.parseInt(getParameter("d"));
	}

	public void paint(Graphics R)
	{
		int MAX=0;

		R.drawLine(50, 450, 900, 450);		// EJE X
		R.drawLine(100, 50, 100, 480);		// EJE Y

		MAX = ValorMaximo(a, b, c, d);

		DibujaBarra(a, 100, MAX, R, Color.blue);		// TRAZO DE A
		DibujaBarra(b, 300, MAX, R, Color.red);            // TRAZO DE B
		DibujaBarra(c, 500, MAX, R, Color.green);            // TRAZO DE C
		DibujaBarra(d, 700, MAX, R, Color.black);            // TRAZO DE D
	}

	void DibujaBarra(int d, int Pos, int MAX, Graphics R, Color color)
	{
		int X, D;
		X = d*400/MAX; D = 450 - X;
		R.setColor(color);
		R.fillRect(Pos, D, 50, X);
	}

	public static void main(String R[]) { new Hola(); }


	int ValorMaximo(int a, int b, int c, int d)
	{
		int MAX = a;
		if (b > MAX) MAX = b;
		if (c > MAX) MAX = c;
		if (d > MAX) MAX = d;

		return MAX;
	}
}