Load resources based upon client environment at startup
import javax.swing.JCheckBox;
public class Main {
public static void main(String[] argv) {
System.out.println((JCheckBox) MyResources.rb.getObject("aCheckbox"));
MyResources.rb.getString("aButton");
MyResources.rb.getObject("vButton");
}
}
[MyResources.java (default resources)]
import java.text.DecimalFormat;
import java.util.ListResourceBundle;
import java.util.ResourceBundle;
import javax.swing.JButton;
import javax.swing.JCheckBox;
public class MyResources extends ListResourceBundle {
public static ResourceBundle rb = ResourceBundle.getBundle("MyResources");
public Object [][] getContents() {
return contents;
}
static final Object[][] contents = {
{ "aCheckbox", new JCheckBox("Yes") } ,
{ "aButton" , "Today {0,date,long}"},
{ "vButton" , new JButton("Validate number")},
};
}
[MyResources_en.java (english language resources)]
import java.util.ListResourceBundle;
public class MyResources_en extends ListResourceBundle {
public Object [][] getContents() {
return contents;
}
static final Object[][] contents = {
{ "aLabel" , "a Label (en)" }
};
}
[MyResources_fr.java (french language resources)]
import java.util.ListResourceBundle;
import javax.swing.JButton;
import javax.swing.JCheckBox;
public class MyResources_fr extends ListResourceBundle {
public Object [][] getContents() {
return contents;
}
static final Object[][] contents = {
{ "aLabel" , "une tiquette (fr)" } ,
{ "aCheckbox", new JCheckBox("Oui (fr)")} ,
{ "vButton" , new JButton("Validation du nombre")},
{ "numOK" , "Valide!"},
{ "numERR", "Invalide"}
};
}
[MyResources_fr_CA.java (french language (for Canada) resources)]
import java.util.ListResourceBundle;
public class MyResources_fr_CA extends ListResourceBundle {
public Object [][] getContents() {
return contents;
}
static final Object[][] contents = {
{ "aLabel" , "une tiquette (fr CA)" } ,
};
}
Related examples in the same category