I need to upload a file on the torrent to the file system. I use the mpetazzoni / ttorrent library
I want to implement the download indicator torrent file on the panel. I use JProgressBar to display the boot process.
The question is how to get data from Client . to automatically update JProgressBar .
mpetazzoni/ttorren are no mpetazzoni/ttorren to mpetazzoni/ttorren , I use this as the lightest of those that I found. If you know another, more convenient or where there is good documentation - say.

    1 answer 1

    After a small run into the code, it turned out that com.turn.ttorrent.client.Client inherits java.util.Observable (for the first time I see the use of Observable ), so you can do this:

     Client client = startTorrent(); client.addObserver( new Observer() { @Override public void update(Observable o, Object arg) { Client c = (Client)o; // client.info() вылетает, если торрент не инициализирован if ( c.getTorrent().isInitialized() ) { final float completion = c.getTorrent().getCompletion(); System.out.printf( ">>>> torrent is %.2f%% complete.%n", completion ); SwingUtilities.invokeLater( () -> progressBar.setValue( Math.round( completion ) ) ); c.info(); } } }); 

    Callback will be called when changing the state of the torrent and when loading the next piece.