实际上,我正在编写一个小洪水"模拟器"。因此,一种方法是从文件中读取洪泛级别的时间序列,并在窗口中显示它们几秒钟。令人尴尬的是,只显示了最后一个洪水事件,但是从文件中正确读取了所有行(我仔细检查过这个)。
private void timeFlood(File file)
{
System.out.println("timeFlood()");
String path = file.getParent();
String name = file.getName();
BufferedReader reader = null;
String date;
try
{
reader = new BufferedReader(new FileReader(file));
while ((date = reader.readLine()) != null)
{
if(date != null) {
img = model.getFloodedImageWithHeight(Float.parseFloat(date.split(",")[0]),
Float.parseFloat(uncertainty.getText()), floodfill.isSelected());
String percent = String.format("%.2f", model.getPercentFloodedArea() * 100.0f);
percent = percent.split(",")[0] + "." + percent.split(",")[1] + "%";
flooded_area.setText("Flooded Area: " + percent);
level.setText("Waterlevel: " + date.split(",")[0] + " Meters");
icon.setImage(img);
image.setIcon(icon);
image.repaint();
parseTerLegend();*/
Thread.sleep(3000);
}
}
System.out.println("end");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
可能是while循环迭代到快速的问题?那么JLable图像不能足够快地更新自己吗?
感谢您的帮助!