19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

package chapter43;<br />

import java.util.*;<br />

import java.text.*;<br />

public class TimeBean {<br />

private Locale[] allLocale = Locale.getAvailableLocales();<br />

private String[] allTimeZone = TimeZone.getAvailableIDs();<br />

private int localeIndex;<br />

private int timeZoneIndex;<br />

public TimeBean() {<br />

Arrays.sort(allTimeZone);<br />

}<br />

public Locale[] getAllLocale() {<br />

return allLocale;<br />

}<br />

public String[] getAllTimeZone() {<br />

return allTimeZone;<br />

}<br />

public int getLocaleIndex() {<br />

return localeIndex;<br />

}<br />

public int getTimeZoneIndex() {<br />

return timeZoneIndex;<br />

}<br />

public void setLocaleIndex(int index) {<br />

localeIndex = index;<br />

}<br />

public void setTimeZoneIndex(int index) {<br />

timeZoneIndex = index;<br />

}<br />

/** Return a string for the current time<br />

* with the specified locale and time zone */<br />

public String currentTimeString(<br />

int localeIndex, int timeZoneIndex) {<br />

Calendar calendar =<br />

new GregorianCalendar(allLocale[localeIndex]);<br />

TimeZone timeZone =<br />

TimeZone.getTimeZone(allTimeZone[timeZoneIndex]);<br />

DateFormat dateFormat = DateFormat.getDateTimeInstance(<br />

DateFormat.FULL, DateFormat.FULL, allLocale[localeIndex]);<br />

dateFormat.setTimeZone(timeZone);<br />

20

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!