renevanh
11-19-2008, 05:25 PM
While updating/refreshing my Java skills, I run into an error I can't get solved because I just don't understand what could be wrong.
The code of the class I'm working on:
import java.awt.*;
public class Staafdiagram extends MSO{
int r=0, g=0, b=0;
int boven = 50;
public void paint(Graphics gr){
int links = 275;
int breedte = 10;
int hoogte = 5;
Color c = new Color(r,g,b);
for(int x=0; x<allunis.length; x++);
gr.setColor(c);
gr.fillRect(links, boven, breedte, hoogte);
gr.drawString(allunis[x].naam, links+20, boven);
newuni();
}
public void newuni(){
r+=20;
g+=20;
b+=20;
boven+=20;
}
}
The error:
The field Component.x is not visible
It is about the line: gr.drawString(allunis[x].naam, links+20, boven);
Somehow, there is something wrong with allunis or the x itself.
allunis is an array created and populated in the MSO class and is working fine.
Since allunis is a 'global variable' in MSO (ok, it's called different in Java, but I lost it) and the current class extends MSO, it should be working (and it does in the for loop definition).
The quickfix option of Eclipse only suggest to create a local variable x, but that doesn't solve the problem (there is a local x already anyway).
Anyone around who can help me out?
The code of the class I'm working on:
import java.awt.*;
public class Staafdiagram extends MSO{
int r=0, g=0, b=0;
int boven = 50;
public void paint(Graphics gr){
int links = 275;
int breedte = 10;
int hoogte = 5;
Color c = new Color(r,g,b);
for(int x=0; x<allunis.length; x++);
gr.setColor(c);
gr.fillRect(links, boven, breedte, hoogte);
gr.drawString(allunis[x].naam, links+20, boven);
newuni();
}
public void newuni(){
r+=20;
g+=20;
b+=20;
boven+=20;
}
}
The error:
The field Component.x is not visible
It is about the line: gr.drawString(allunis[x].naam, links+20, boven);
Somehow, there is something wrong with allunis or the x itself.
allunis is an array created and populated in the MSO class and is working fine.
Since allunis is a 'global variable' in MSO (ok, it's called different in Java, but I lost it) and the current class extends MSO, it should be working (and it does in the for loop definition).
The quickfix option of Eclipse only suggest to create a local variable x, but that doesn't solve the problem (there is a local x already anyway).
Anyone around who can help me out?