Java Reference
In-Depth Information
Calling the setNation method in this class sets the current nation. That makes the wizard alter the Currency
setting, the PhoneNumber , and a set of localized language strings, InternationalizedText .
Example A.164 Currency.java
1. import java.text.NumberFormat;
2. public class Currency{
3. private char currencySymbol;
4. private NumberFormat numberFormat;
5.
6. public void setCurrencySymbol(char newCurrencySymbol){ currencySymbol =
newCurrencySymbol; }
7. public void setNumberFormat(NumberFormat newNumberFormat){ numberFormat =
newNumberFormat; }
8.
9. public char getCurrencySymbol(){ return currencySymbol; }
10. public NumberFormat getNumberFormat(){ return numberFormat; }
11. }
Example A.165 InternationalizedText.java
1. import java.util.Properties;
2. import java.io.File;
3. import java.io.IOException;
4. import java.io.FileInputStream;
5. public class InternationalizedText{
6. private static final String DEFAULT_FILE_NAME = "";
7. private Properties textProperties = new Properties();
8.
9. public InternationalizedText(){
10. this(DEFAULT_FILE_NAME);
11. }
12. public InternationalizedText(String fileName){
13. loadProperties(fileName);
14. }
15.
16. public void setFileName(String newFileName){
17. if (newFileName != null){
18. loadProperties(newFileName);
19. }
20. }
21. public String getProperty(String key){
22. return getProperty(key, "");
23. }
24. public String getProperty(String key, String defaultValue){
25. return textProperties.getProperty(key, defaultValue);
26. }
27.
28. private void loadProperties(String fileName){
29. try{
30. FileInputStream input = new FileInputStream(fileName);
31. textProperties.load(input);
32. }
33. catch (IOException exc){
34. textProperties = new Properties();
35. }
36. }
37. }
Example A.166 PhoneNumber.java
1. public class PhoneNumber {
2. private static String selectedInterPrefix;
3. private String internationalPrefix;
4. private String areaNumber;
5. private String netNumber;
6.
7. public PhoneNumber(String intPrefix, String areaNumber, String netNumber) {
8. this.internationalPrefix = intPrefix;
9. this.areaNumber = areaNumber;
10. this.netNumber = netNumber;
11. }
12.
13. public String getInternationalPrefix(){ return internationalPrefix; }
14. public String getAreaNumber(){ return areaNumber; }
15. public String getNetNumber(){ return netNumber; }
16. public static String getSelectedInterPrefix(){ return selectedInterPrefix; }
17.
Search WWH ::




Custom Search