Archive | Java RSS feed for this section

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'));

Arabic to Roman Numerals in JAVA

5 Mar

This function will execute the conversion of Arabic number into Roman number.

public static String ArabicToRoman(int aNumber){

if(aNumber < 1 || aNumber > 3999){
return "-1";
}

int[] aArray = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
String[] rArray = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
String rNumber = "";

for(int i=0; i= aArray[i]){
rNumber += rArray[i];
aNumber -= aArray[i];
}
}

return rNumber;
}