Friday, May 4, 2012

Dynamically increasing int value on JFrame

I was trying to have a counter in the shape of jLabel on the JFrame that increases its value automatically .

My purpose was to mimic a heart rate of a person so that I would follow further operations based on this value.   I created an arrayList and made it full of integer heart rate values previously recorded in a txt  file. By using SwingWorker class defined in this example,  I was able to get an integer from the list, send it (by publish function) and catch it on the air and write it into label.  By this way I had an application that shows me the hearRate of a person as if it is in real time.

Check this Flipper example. 

Code explanation

Friday, April 27, 2012

Java tips 1 = Three dots ...

 Variable Length Arguments -

The cal method has a parameter "a" that is an integer.
But the trick is "..." three dots, meaning that  a is actually an integer array with unknown size. Btw, I can send 5 parameters, 10 ,400 ,500  , it doesnt matter.

public class shama {
    public static void main(String[] args) {
    public static void cal (int...a)
       for(int x:a)
         System.out.println("vals: " + x);

Result ; 

vals: 15
vals: 24
vals: 32
vals: 1
vals: 2
vals: 5
vals: 3
vals: 242
vals: 52