JavaFX speed o meter

By qless on Friday 26 June 2009 18:22 - Comments (7)
Category: JavaFX, Views: 1.633

I've did another test application in JavaFX, its a (bit of) remake of my old java download speed meter applet.

Screenshot:
Screenshot javaFX speed o meter

To run the application: click here


The old applet looks like this:
http://www.hierzo.net/images/screenshottest.png
And can be found here

For the old applet I had to hack the HTTPConnection class to be able to report a speed during the transfer, creating Listeners and so on. In JavaFX that isn't necessary:

Java:
1
2
3
4
5
6
7
8
9
10
11
12
function downloadFile() {
    downloadRequest = HttpRequest {
        locationsome url;
        sinkdata;

        onStartedfunction() {
            timer.play();
            timestart = System.currentTimeMillis();
        }
    }
    downloadRequest.start();
}


And than just put your own Timer on it to report the progress:

Java:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var timerTimeline = Timeline {
        repeatCount20
        keyFrames:
        [
        KeyFrame {
            time1s
            actionfunction() {
                downloadspeedUpdate();
            }
        }]
        }

function downloadspeedUpdate() {
    timeDone = (System.currentTimeMillis()-timestart);
    currentSpeed  = (downloadRequest.read - lastRead)/1024.0*8.0;
    avgSpeed = (downloadRequest.read/1024.0*8.0) / ((System.currentTimeMillis()-timestart)/1000);
    if (currentSpeed > maxSpeed) {
        maxSpeed = currentSpeed;
    }
    lastRead = downloadRequest.read;
}


And to update the label on the screen, just declare it like this:

Java:
1
2
3
4
5
6
Text {
   fontFont {
      size20;
   }
   contentbind "{%.2f Main.currentSpeed/1024}";
}

Notice the keyword "bind", that will tell javaFX to update this text node as soon as the Main.currentSpeed variable is updated. No more listeners!

I wanted to do an upload test too, but I've hit a bug...so that's now submitted to the development team of javafx here

Volgende: Chateau Feuille de Laurier 06-'09 Chateau Feuille de Laurier
Volgende: Crashing with humor 06-'09 Crashing with humor

Comments


By T.net user Neverwinterx, Friday 26 June 2009 19:19

Quite annoying that the application is installed and even makes a shortcut on the desktop. Any way to disable this?

By T.net user qless, Friday 26 June 2009 20:16

Quite annoying that the application is installed and even makes a shortcut on the desktop. Any way to disable this?
Sorry for the shortcut, I can disable that with the jnlp file. The app isn't installed, only cached

By T.net user Neverwinterx, Friday 26 June 2009 20:59

Well I mean that it is listed in the Programs in Vista. Is it automatically removed after a while?

By T.net user Alex), Saturday 27 June 2009 05:23

Maybe it's my laptop, but around 90% it started using 50% of CPU (dual core machine) which made everything go very sluggish. I do hope this is not intended behavior?

By WoBBeL, Saturday 27 June 2009 10:44

Hij zegt dat ik 20 mbps haal...en ik heb maar 8mbps thuis :')

By T.net user HyperBart, Saturday 27 June 2009 17:35

Ben jij de beheerder van userbase? die speedtest daar gebruik ik wel eens, maar deze komt er precies ook wel accuraat mee voor de dag !

By T.net user qless, Saturday 27 June 2009 23:06

Nope, ik ben geen beheerder, had een opzetje gemaakt als vervanging van de speedtest maar is er door drukte niet van gekomen...

Comment form
(required)
(required, but will not be displayed)
(optional)

Please enter the code from the image below: