JComboBox Key – Value Pair

8 Jul

To create JComboBox with key and value first create next class:

public class myItemS {

    public String key, value;

    KorakItem(String key_, String value_) {
        key = key_;
        value = value_;
    }

    public String getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    @Override
    public String toString() {
        return value;
    }
}

After that you can use this class in the following way:

// cmbMyCMB is already created object @JCombobox
cmbMyCMB.addItem(new myItemS('0','JAVA'));
cmbMyCMB.addItem(new myItemS('1','C#'));
cmbMyCMB.addItem(new myItemS('2','PHP'));

Euros to US Dollars Currency converter

8 Jul

I had enough free time to create a simple and useful thing. It is a currency converter that is convert euro to dollar and dollar to euro. It is located at the following address:

EURO 2 USD

Refresh and Resort jQuery Tablesorter Table

17 Jun

If you need to load data in tablesorter table with AJAX (for example) you need to update and resort tablesorter table after load data with code below.

$(".tablesorter").trigger("update");
$(".tablesorter").trigger("sorton",[[0,0]]); // sort first column asc

NetBeans 6.8 JAVA Code Auto-Complete

25 May

To activate auto-complete code, in NetBeans 6.8 ( for Java IDE ), go to
Tools -> Options -> Editor -> Code Completion
Select “JAVA” in Language combo box
Check “Auto Popup on Typing any Java Identifier Part
Restart NetBeans 6.8 and enjoy.

Get the text of the selected item in ComboBox with jQuery

3 Apr

Get text:

 $("#ComboBox option:selected").text()

and get HTML:

 $("#ComboBox option:selected").html()

CheckBox sa jQuery Framework-om

14 Mar

jQuery je JavaScript framework koji u velikoj mjeri može da pojednostavi JavaScript kodiranje bez da razmišljate o kompatibilnosti browser-a.
Jedna od prednosti jQuery-ja jednostavnost manipulacije elementima i njihovim atributima. U ovom postu ću, na jednostavan način, da pokažem neke od mogućnosti jQuery-ja.

Uzmimo element checkbox  i manipulišimo njegovim atributom checked.
Ovo je HTML kod jednostavne forme sa dva checkbox-a i dva dugmeta.

        <form name="myform" id="myform" action="javascript:void(null)">
            <input type="checkbox" id="preview" name="preview" value="1" /> Preview.<br />
            <input type="checkbox" id="sendresponse" name="sendresponse" value="1" /> Send response.<br /> <br />
            <input type="button" id="checkall" value="Check all" />
            <input type="button" id="uncheckall" value="UnCheck all" />
        </form>

Cilj nam je da klikom na dugme CheckAll svi checkbox-ovi postanu označeni, a klikom na dugme UnCheckAll postanu neoznačeni.

Ovo je kompletan jQuery kod:

            jQuery(document).ready(function(){
                // check all
                $('#checkall').click(function(){
                    $('#myform input:checkbox').each(function(){
                        $(this).attr('checked', true);
                    });
                });
                // uncheck all
                $('#uncheckall').click(function(){
                    $('#myform input:checkbox').each(function(){
                        $(this).attr('checked', false);
                    });
                });
            });

Prođimo kroz ovaj kod korak po korak:

1. Ovim kodom jQuery provjerava document i ceka da on bude spreman za manipulisanje.

$(document).ready(function(){

});

2. Dodajemo event click na dugme čiji je id checkall

                $('#checkall').click(function(){

                });

3. Unutar event-a click pomoću selector-a označimo sve checkbox-ove unutar forme čiji je id myform.
To ćemo učiniti pomoću ovog koda:

                    $('#myform input:checkbox').each(function(){

                    });

4. Sada nam samo ostaje da označimo svaki checkbox što ćemo da učinimo na sljedeći način:

$(this).attr('checked', true);

Ovaj kod bi mogao da se napiše na drugi način, kao recimo:

$(this).attr('checked','checked');

I obavljao bi istu funkciju kao i prethodni kod.
5. Da bismo osposobili dugme UnCheckAll koristićemo isti kod koji smo koristili za CheckAll dugme s tim što ćemo da napravimo sljedeću izmjenu:

$(this).attr('checked', true);
// prelazi u
$(this).attr('checked', false);

Ovaj dio koda bi takođe mogao da se napiše na drugi način i to kao:

$(this).attr('checked','');

I to je to, jednostavno i lako ;)

Kod radi na testiranim browser-ima:

  • Chrome 5.0.342.3
  • Mozilla Firefox 3.6
  • Opera 10.50 Beta
  • Internet Explorer 8.0
  • Safari 4.0.4

Demo

Preview.

Send response.

JavaScript Email Validation

12 Mar

This function validates email address format.
Function returns true if format is valid and false if format is invalid.

function validate(address /* as string */) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(address) == false) {
      return false;
   }
      return true;
}
Page 1 of 212