Hi... I'm a newbie at Java, so I was wondering if you guys could help me out...
I have txt file i'm reading scores and labels off of to make a bar graph.
First line is an integer (score), second line is the label ("Score 1"), and they alternate from then on. I have 5 scores, meaning ten lines in the txt file.
Anyway, I can read the txt file and make the bar graph perfectly, but when i make the loop, i always have to specify how many times to do the loop... I have no idea how to make it count how many items are in the txt file automatically or to stop when there are no more values.
Please help if you can :o
Here is my code for the loop area so far:
int n = 0;
int itemCount = 5;
SimpleReader reader = new SimpleReader( "graphdata.dat" );
while ( n < itemCount )
{
double number = reader.getInt();
r = new SimpleRectangle( BAR_START, barPos, (int) number, BAR_HEIGHT );
r.setColor( barColor );
r.setToFill();
graphWin.add( r );
total = total + number;
n = n + 1;
barPos = barPos + BAR_HEIGHT + BAR_SPACER;
String word = reader.getString();
lab = new SimpleLabel( LABEL_START, labelPos, LABEL_WIDTH, LABEL_HEIGHT );
lab.setText( word + ": " + (int) number );
graphWin.add( lab );
labelPos = labelPos + LABEL_HEIGHT + LABEL_SPACER;
}
reader.safeClose();
the overhead for the application is so low its negligible. I find it more convenient to have it as a launcher, saves digging through multiple applications.
Question
khaos34
Hi... I'm a newbie at Java, so I was wondering if you guys could help me out...
I have txt file i'm reading scores and labels off of to make a bar graph.
First line is an integer (score), second line is the label ("Score 1"), and they alternate from then on. I have 5 scores, meaning ten lines in the txt file.
Anyway, I can read the txt file and make the bar graph perfectly, but when i make the loop, i always have to specify how many times to do the loop... I have no idea how to make it count how many items are in the txt file automatically or to stop when there are no more values.
Please help if you can :o
Here is my code for the loop area so far:
Link to comment
https://www.neowin.net/forum/topic/62996-java-reading-file-loop-help/Share on other sites
6 answers to this question
Recommended Posts