150 likes | 338 Views
class Locale 1/3. Constructor Locale(String, String) Construct a locale from language, country. Locale(String, String, String) Construct a locale from language, country, variant. Methods clone() equals(Object) getCountry() uppercased two-letter ISO-3166 getDefault()
E N D
class Locale 1/3 • Constructor Locale(String, String) Construct a locale from language, country. Locale(String, String, String) Construct a locale from language, country, variant. • Methods clone() equals(Object) getCountry() uppercased two-letter ISO-3166 getDefault() getDisplayCountry() getDisplayCountry(Locale) getDisplayLanguage() getDisplayLanguage(Locale) getDisplayName() getDisplayName(Locale) getDisplayVariant() getDisplayVariant(Locale) getISO3Country() three-letter ISO country abbreviation getISO3Language() three-letter ISO language abbreviation getLanguage() lowercased two-letter ISO-639 getVariant() hashCode() setDefault(Locale) toString()
class Locale 2/3 import java.util.Locale; public class GetLocale { public static void main( String args[ ] ) { Locale locale = new Locale( "ko", "KR" ); Locale locale_er = new Locale( "error", "ERROR" ); System.out.println( locale ); System.out.println( Locale.getDefault( ) ); System.out.println( locale.getISO3Language( ) ); System.out.println( locale.getISO3Country( ) ); System.out.println( locale.getDisplayLanguage( ) ); System.out.println( locale_er ); System.out.println( Locale.FRENCH ); System.out.println( Locale.FRANCE ); } }
class Locale 3/3 gura:~/Java/Seminar/java.util> java GetLocale ko_KR en kor KOR Korean error_ERROR fr fr_FR
class TimeZone 1/5 • Constructor TimeZone() • Methods clone() Overrides Cloneable getAvailableIDs() Gets all the available IDs supported. getAvailableIDs(int) getDefault() getID() Gets the ID of this time zone. getOffset(int, int, int, int, int, int) Gets the time zone offset, for current date, modified in case of daylight savings. getRawOffset() Gets unmodified offset, NOT modified in case of daylight savings. getTimeZone(String) Gets the TimeZone for the given ID. inDaylightTime(Date) Queries if the given date is in Daylight Savings Time in this time zone. setDefault(TimeZone) setID(String) Sets the time zone ID. setRawOffset(int) Sets the base time zone offset to GMT. useDaylightTime() Queries if this time zone uses Daylight Savings Time.
class TimeZone 2/5 • Abstract Class. • TimeZone represents a time zone offset, and also figures out daylight savings. • TimeZone tz = TimeZone.getTimeZone("PST"); • Typically, you get a TimeZone using getDefault which creates a TimeZone based on the time zone where the program is running. For example, for a program running in Japan, getDefault creates a TimeZone object based on Japanese Standard Time.
class TimeZone 3/5 public static synchronized String[] getAvailableIDs() public static synchronized TimeZone getDefault() Gets the default TimeZone for this host. public abstract boolean inDaylightTime(Date date) Queries if the given date is in Daylight Savings Time in this time zone. public abstract boolean useDaylightTime() Queries if this time zone uses Daylight Savings Time. public abstract int getRawOffset() Gets unmodified offset, NOT modified in case of daylight savings. This is the offset to add *to* UTC to get local time. public static synchronized TimeZone getDefault() Gets the default TimeZone for this host.
class TimeZone 4/5 public class TimeZoneTest { public static void main( String args[ ] ) { //TimeZone Test = new TimeZone( ); System.out.println( TimeZone.getDefault( ) ); //System.out.println( Test.getRawOffset( ) ); String Test2[ ]; Test2=TimeZone.getAvailableIDs System.out.println( Test2.length - 1 ); for(inti=0;i<Test2.length;i++) { System.out.println( Test2[ i ] ); } } }
class TimeZone 5/5 gura:~/Java/Seminar/java.util> java TimeZoneTest java.util.SimpleTimeZone@1b773f4 30 GMT ECT EET ART EAT MET NET PLT IST BST VST CTT JST ACT AET SST NST MIT HST ... ...
class ResourceBundle 1/3 • Constructor ResourceBundle() • Methods getBundle(String) Get the appropriate ResourceBundle subclass. GetBundle(String, Loca) Get the appropriate ResourceBundle subclass. getKeys() Return an enumeration of the keys. getObject(String) Get an object from a ResourceBundle. getString(String) Get an object from a ResourceBundle. getStringArray(String) Get an object from a ResourceBundle. handleGetObject(String) Get an object from a ResourceBundle. setParent(ResourceBundle) Set the parent bundle of this bundle.
class ResourceBundle 2/3 • This allows you to write programs that can: • be easily localized, or translated, into different languages • handle multiple locales at once • be easily modified later to support even more locales • baseclass must be fully qualified : myPackage.MyResources • baseclass with no suffixes baseclass + "_" + language1 + "_" + country1 + "_" + variant1 baseclass + "_" + language1 + "_" + country1 baseclass + "_" + language1 baseclass baseclass + "_" + language2 + "_" + country2 + "_" + variant2 baseclass + "_" + language2 + "_" + country2 baseclass + "_" + language2 • key/value pairs : keys are always Strings • parent • handleGetObject( String key ), getKeys( ) • only these are abstract methods.
class ResourceBundle 3/3 import java.util.ResourceBundle; import java.util.Locale; class MyResourceTester { public static void main( String args[ ] ) { ResourceBundle myResource = ResourceBundle.getBundle( "MyResource", Locale.FRANCE ); System.out.println( myResource.getString( "s6" ) ); myResource = ResourceBundle.getBundle( "MyResource” ); System.out.println( myResource.getString( "s6" ) ); } } gura:~/Java/Seminar/java.util> java MyResourceTester pas de files no files
class PropertyRe...dle 1/2 public PropertyResourceBundle(InputStream stream) throws IOException Creates a property resource Parameters: file - property file to read from. public Object handleGetObject(String key) Override of ResourceBundle, same semantics Overrides: handleGetObject in class ResourceBundle public Enumeration getKeys() Implementation of ResourceBundle.getKeys. Overrides: getKeys in class ResourceBundle description.
class PropertyRe...dle 2/2 s1=3 s2=MeinDisk s3=3 Mar 96 s4=Der disk '{1}' a {0} a {2}. s5=0 s6=keine Datein s7=1 s8=ein Datei s9=2 s10={0}|3 Datein s11=Der Format worf ein Exception: {0} s12=ERROR s14=Resulte s13=Dialogue s15=Pattern s16=1,3 • keys are case-sensitive
class ListRe...dle 1/2 public ListResourceBundle() public final Object handleGetObject(String key) Override of ResourceBundle, same semantics Overrides: handleGetObject in class ResourceBundle public Enumeration getKeys() Implementation of ResourceBundle.getKeys. Overrides: getKeys in class ResourceBundle protected abstract Object[][] getContents()
class ListRe...dle 2/2 import java.util.ResourceBundle; import java.awt.Dimension; import java.util.ListResourceBundle; public class MyResource extends ListResourceBundle { public Object[][] getContents() { return contents; } static final Object[][] contents = { // LOCALIZE THIS {"s1", "3"}, {"s2", "MyDisk"}, {"s3", "3 Mar 96"}, {"s4", "The disk '{1}' contained {0} on {2}."}, {"s5", "0"}, {"s6", "no files"}, {"s7", "1"}, {"s8", "one file"}, {"s9", "2"}, {"s10", "{0}|3 files"}, {"s11", "format threw an exception: {0}"}, {"s12", "ERROR"}, {"s14", "Result"}, {"s13", "Dialog"}, {"s15", "Pattern"}, {"s16", new Dimension(1,5)} // END OF MATERIAL TO LOCALIZE }; }