I'm trying to make a progress bar or something like that in my program that is sending files to a server. I've this
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject(file.getName());
FileInputStream fis = new FileInputStream(file);
byte [] buffer = new byte[Server.BUFFER_SIZE];
Integer bytesRead = 0;
jj = size-bytesRead;
int i = 0;
while ((bytesRead = fis.read(buffer)) > 0) {
oos.writeObject(bytesRead);
jButton3.doClick();
oos.writeObject(Arrays.copyOf(buffer, buffer.length));
}
oos.close();
ois.close();
And this is Button3
temp = temp - 100;
jLabel3.setText(String.valueOf(temp));
temp
is a size of chosen file and I'm subtracting 100 because it's the size of bytes in every step in the loop.
The problem is when I start sending file, Button3 is grayed till the end of sending doing nothing visible with label (like it is too slow to update the label on time) but at the end it's displaying a right data.
Why it can't periodically update the label? What should I do to fix that? Thanks for any advice.