gpt4 book ai didi

java - 尝试附加一行文本时窗口出现 "see-through"- Java

转载 作者:太空宇宙 更新时间:2023-11-04 08:51:16 25 4
gpt4 key购买 nike

我正在尝试将百分比附加到 java 中的文本区域。它涉及一个循环,该循环确定百分比,然后将其附加到另一个包含文本区域的 JFrame。

“pro”类只有一个带有 JtextArea 的窗口。

我遇到的问题是窗口似乎显示了下面的窗口,就好像它滞后一样。有没有办法解决这个问题。我尝试查看 SwingWorker 但发现它令人困惑。任何帮助将不胜感激。以下是该程序的摘录。

public void copy(File sourceLocation, File targetLocation) throws IOException {

if (sourceLocation.isDirectory()) {
if (!targetLocation.exists()) {
targetLocation.mkdir();
}

String[] children = sourceLocation.list();
for (int i=0; i<children.length; i++) {

int length = children.length - 1;

float percentage = (i/(float)length) *100;
String d = percentage + "%" + " " + sourceLocation;
System.out.println(percentage + "%" + " " + sourceLocation);

pro.area.append(percentage + "\n");




copy(new File(sourceLocation, children[i]),
new File(targetLocation, children[i]));
}
} else {

InputStream in = new FileInputStream(sourceLocation);
OutputStream out = new FileOutputStream(targetLocation);

// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
//pro.setVisible(false);
}

}

最佳答案

图形异常可能是由于阻止 event dispatch threadSwingWorker是首选方法;但使用 continuations as objects是一种替代方案,如图 here .

关于java - 尝试附加一行文本时窗口出现 "see-through"- Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3282925/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com