Hello I have an application that loads in values. The values are x,y,and a string value. I want to know how to load in a string because I only know how to o it with an integer. Take a look at this code:
public static void loadStars() {
try {
BufferedReader bf = new BufferedReader(new FileReader ("files/cards.txt"));
for (int i = 0; i < 10; i++) {
String line;
while ((line = bf.readLine()) != null) {
String[] args = line.split(" ");
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
String name = Integer.parseInt(args[2]);
play.s.add(new Star(x,y,name));
}
}
bf.close();
} catch (Exception e) {
e.printStackTrace();
}
}
I have
play.s.add(new star(x,y,name));
I know how to load in x and y but I don't know how to load in name.
Please help me.
Edit----
In the file that is loaded in it is formatted like this:
x y name
example:
10 10 jack
100 500 conor
each star is represented by 1 line.
public class Star extends BasicStar {
private Image img;
public Star(int x, int y,String starname) {
this.x = x;
this.y = y;
this.starname = starname;
r = new Rectangle(x, y, 3, 3);
}
public void tick() {
if (r.contains(Comp.mx, Comp.my) && Comp.ml) {
remove = true;
}
}
public void render(Graphics g) {
if (!displaySolar) {
ImageIcon i2 = new ImageIcon("res/planets/star.png");
img = i2.getImage();
g.drawImage(img, x, y, null);
}
}
}