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);
}
}