extends List Resource bundle : ListResourceBundle « I18N « Java






extends List Resource bundle

 

import java.util.Enumeration;
import java.util.ResourceBundle;
import java.util.MissingResourceException;

public class SimpleResourceBundleExample {

  public static void main(String [] argv) {
    try {
      ResourceBundle rb = ResourceBundle.getBundle("SimpleResourceBundle");

      System.out.println(rb.getString("AMMessage"));
      System.out.println(rb.getString("PMMessage"));

    } catch (MissingResourceException mre) {
      mre.printStackTrace();
    }
  }
}

import java.awt.*;
import java.util.*;

public class SampleResourceBundle extends ListResourceBundle {

  public Object [][] getContents() {
    return contents;
  }

  static final Object [][] contents = {
      {"okButton", new Button("OK")},
      {"negativeInteger", new Integer(-1)},
      {"textString", "Thank you for reading our book"}
  };
}


import java.util.Enumeration;
import java.util.ResourceBundle;
import java.util.StringTokenizer;

public class SimpleResourceBundle extends ResourceBundle {

  private String keys = "AMMessage PMMessage";

  public Object handleGetObject(String key) {
    if (key.equals("AMMessage")) return "Good morning";
    if (key.equals("PMMessage")) return "Good evening";

    return null;
  }

  public Enumeration getKeys() {
    StringTokenizer keyTokenizer = new StringTokenizer(keys);

    return keyTokenizer;
  }
}


public class SimpleResourceBundle_it extends SimpleResourceBundle {

  public Object handleGetObject(String key) {
    if (key.equals("AMMessage")) return "Buona mattina";
    if (key.equals("PMMessage")) return "Buona sera";

    return null;
  }
}

 








Related examples in the same category

1.Text Bundle
2.Your own Resource Bundle based on ListResourceBundle