我希望我的扫描仪读取.txt
文件并找到三个整数int1 int2 int3
并将它们用作颜色代码。唯一的问题是,我不知道该怎么做。
到目前为止,我有:
@SuppressWarnings("resource")
Scanner[] properties = new Scanner[str];
Color[] colour = new Color[str];
int posx = 200;
int posy = 100;
for (int i = 0; i < str; i++){
properties[i] = new Scanner(new File("Particles/" + string[i] + ".txt"));
g.drawString("Particles/" + string[i] + ".txt", 200, posy);
colour[i] = new Color(properties[i].nextInt(), properties[i].nextInt(),properties[i].nextInt());
posy = posy + 100;
}
(它只是方法的一部分,这就是为什么str
没有声明等)。
我正在读取的文件看起来像:
Name: Fire
Color: 255 0 0
Speed: 0
Size: 1
我如何让它阅读255 0 0
并用作颜色?