Ciao, ho il seguente codice
class DrawSinEmo extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
int width = getWidth ();
int height = getHeight ();
int c = height/2;
int i=8459;
int x;
g.drawLine(0,c,width,c);
int t =width/10;
int p, y;
for (p=0, x=0; x<width ;x+=10)
{p++;}
int ay[] = new int[p];
int ay23[] = new int[p];
int ay33[] = new int[p];
int ax[] = new int[p];
double r;
p=0;
for (x=0; x<width ;x+=10)
{
r = Math.sin (i/28.0* 2*Math.PI);
y = (int) (c-200 * r);
ay[p] = y;
ax[p] = x;
if( p > 0 ) g.drawLine (ax[p-1],ay[p-1],ax[p],ay[p]);
r = Math.sin (i/23.0* 2*Math.PI);
y = (int) (c-200 * r);
ay23[p] = y;
if( p > 0 ) g.drawLine (ax[p-1],ay23[p-1],ax[p],ay23[p]);
r = Math.sin (i/33.0* 2*Math.PI);
y = (int) (c-200 * r);
ay33[p] = y;
if( p > 0 ) g.drawLine (ax[p-1],ay33[p-1],ax[p],ay33[p]);
i++;
p++;
}
//Numerazione asse x --> ogni unità = 100px e 10 giorni
int valore = 0, confronto;
String l ="";
g.setColor(Color.black);
for (x=0, confronto=0; x<width ;x+=10, confronto++)
{
l = String.valueOf(valore);
if ((confronto%10)==0) {
g.drawString(l, x, c+20);
g.drawLine (x, c+5, x, c-5);
valore++;
}
}
}
}
Richiamato nel seguente modo:
DrawSinEmo sin1= new DrawSinEmo();
JFrame application = new JFrame("BIO");
application.setDefaultCloseOperation(JFrame.EXIT_O N_CLOSE);
application.add(sin1);
application.setSize(600,480);
application.setVisible(true);
Come devo fare per passare un parametro di tipo int al metodo paintComponent (o alla su classe DrawSinEmo, ditemelo voi)?
In poche parole la variabile che ha attualmente il nome di i deve essere in realtà essere passata come parametro!
Come si può fare?

Rispondi quotando

