Comment tracer facilement un graphique avec barre simplement

Contenu du snippet

montre simplement le principe de création d'une applet qui trace un graphique avec des barres de façon simple.

Source / Exemple :


import java.awt.*;
import java.applet.*;

public class repere extends Applet {
Font clockFaceFont;
Color repereColor;
Color graduationColor;

public void init() {
//setBackground(Color.gray);

repereColor = Color.blue;
graduationColor=Color.red;
}

public void plotrepere(int x0,int y0,int x,int y,Graphics g) {
g.drawLine(x0,y0,x,y);//horizontal
g.drawLine(x,y,y,y);//vertical
}

public void plotgraduation(int x0,int y0,int g0,Graphics g) {
int i;
	for(i=0;i<g0;i++){
		g.drawLine(x0+(10*i),y0-5,x0+(10*i),y0+5);//axe horizontal
		g.drawLine(x0-5,y0-(10*i),x0+5,y0-(10*i));//axe vertical
	}
}

public void tracebar (int posX,int haut,Graphics g){
g.fill3DRect(posX,200-haut,20,haut,false);

}

public void tracegraphe(int x0,int x1,int x2,int x3,int x4, int x5,
								int x6,int x7,int x8,int x9,Graphics g){
tracebar(20,x0,g);
tracebar(40,x1,g);
tracebar(60,x2,g);
tracebar(80,x3,g);
tracebar(100,x4,g);
tracebar(120,x5,g);
tracebar(140,x6,g);
tracebar(160,x7,g);
tracebar(180,x8,g);
tracebar(200,x9,g);
}

public void paint(Graphics g){
	g.setColor(repereColor);
	plotrepere(20,20,20,200,g);
	g.setColor(graduationColor);
	plotgraduation(20,200,20,g);
	//g.drawRect(40,100,20,100);//(x,y,largeur,hauteur)
	g.setColor(Color.cyan);
	//g.fillRect(70,120,20,80);
	//g.setColor(Color.green);
	//g.fill3DRect(100,80,20,120,false);//(x,y,largeur,hauteur,couleur inversé)
	//setBackground(Color.gray);
	tracegraphe(20,40,70,30,10,20,60,60,75,10,g);
 }
}

Conclusion :


merci de vos comentaires eventuels

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.