资源描述:
《Java语言程序设计与数据结构 基础篇原书第11版PPT及其他教辅资源36slide.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1Chapter36Internationalization2ObjectivesTodescribeJava'sinternationalizationfeatures(§36.1).Toconstructalocalewithlanguage,country,andvariant(§36.2).Todisplaydateandtimebasedonlocale(§36.3).Todisplaynumbers,currencies,andpercentagesbasedonlocale(§36.4).Todevelopapplicationsforinternationalaudie
2、ncesusingresourcebundles(§36.5).TospecifyencodingschemesfortextI/O(§36.6).3Java’sInternationalSupport1.UseUnicode2.ProvidetheLocaleclasstoencapsulateinformationaboutaspecificlocale.ALocaleobjectdetermineshowlocale-sensitiveinformation,suchasdate,time,andnumber,isdisplayed,andhowlocale-sensitiveo
3、perations,suchassortingstrings,areperformed.3.UsetheResourceBundleclasstoseparatelocale-specificinformationsuchasstatusmessagesandtheGUIcomponentlabelsfromtheprogram.TheinformationisstoredoutsidethesourcecodeandcanbeaccessedandloadeddynamicallyatruntimefromaResourceBundle,ratherthanhard-codedint
4、otheprogram.4TheLocaleClassALocaleobjectrepresentsaspecificgeographical,political,orculturalregion.AnoperationthatrequiresaLocaletoperformitstaskiscalledlocale-sensitive.YoucanuseLocaletotailorinformationtotheuser.5CreatingaLocaleTocreateaLocaleobject,youcanusethefollowingconstructorinLocalecla
5、ss:Locale(Stringlanguage,Stringcountry)Locale(Stringlanguage,Stringcountry,Stringvariant)Example:newLocale(“en”,“US”);newLocale(“fr”,“CA”);Locale.CANADALocale.CANADA_FRENCH6TheLocale-SensitiveOperationsAnoperationthatrequiresaLocaletoperformitstaskiscalledlocale-sensitive.Displayinganumberasadat
6、eortime,forexample,isalocale-sensitiveoperation;thenumbershouldbeformattedaccordingtothecustomsandconventionsoftheuser'slocale.SeveralclassesintheJavaclasslibrariescontainlocale-sensitivemethods.Date,Calendar,DateFormat,andNumberFormat,forexample,arelocale-sensitive.Allthelocale-sensitiveclasses
7、containastaticmethod,getAvailableLocales(),whichreturnsanarrayofthelocalestheysupport.Forexample,Locale[]availableLocales=Calendar.getAvailableLocales();returnsallthelocalesforwhichcalendarsareinstalled.7ProcessingDateandTim