小弟刚来做J2SE,现在我有一个国际化有关的问题.
我想实现的是如下功能:
我的窗口下显示一种语言,然后我有一个BUTTON,用来将整个界面切换到英文或其他语言.
国际化方面的类已经写好了,如下:
import java.util.*;import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;public class UIInternational {    private static final Log logger = LogFactory
                                      .getLog(UIInternational.class);
    private static UIInternational uiInternational = null;
    private static final String PROPSFILENAME = "posbg_messages";
    //默认语言为中文
    public static final String DEFAULT_LANGUAGE = "zh";
    //默认字符集为简体中文
    public static final String DEFAULT_COUNTRY = "CN";    private static String language = null;
    private static String country = null;
    private static Locale locale = null;
    private static ResourceBundle bundle = null;    private UIInternational() {    }    synchronized public static UIInternational getInstance() {
        if (uiInternational == null) {
            uiInternational = new UIInternational();
        }
        return uiInternational;
    }    public static void init() {
        locale = new Locale(DEFAULT_LANGUAGE, DEFAULT_COUNTRY);
        File sourceFile = new File("config/"+ PROPSFILENAME + "_" + locale.toString() +
                                   ".properties");
        if (sourceFile.exists()) {
            FileInputStream is = null;
            try {
                is = new FileInputStream(sourceFile);
                bundle = new PropertyResourceBundle(is);
                if (bundle == null) {
                    logger.error("********bundle source file faild********");
                    return;
                }            } catch (FileNotFoundException ex) {
                logger.error("Can not found file: " + sourceFile.getName());
            } catch (IOException ex) {
                logger.error(ex.toString());
            }        }    }    public static void change(String language, String country) {        if (language == null || country == null) {
            logger.error(
                    "language or country is null,locale will be set the default value " +
                    DEFAULT_COUNTRY + "_" + DEFAULT_LANGUAGE);
            //locale.setDefault(new Locale(language, country));
            return;
        }else{
             locale = new Locale(language, country);
             logger.info(locale.toString());
        }        File sourceFile = new File("config/" + PROPSFILENAME + "_" + locale.toString() +
                                   ".properties");
        if (sourceFile.exists()) {
            FileInputStream is = null;
            try {
                is = new FileInputStream(sourceFile);
                bundle = new PropertyResourceBundle(is);
                if (bundle == null) {
                    logger.error("********bundle source file faild********");
                    return;
                }            } catch (FileNotFoundException ex) {
                logger.error("Can not found file: " + sourceFile.getName());
            } catch (IOException ex) {
                logger.error(ex.toString());
            }
        }    }    public static String getMessages(String message) {
        return bundle.getString(message);    }
    public static void main(String[] args) {
        UIInternational ui = new UIInternational();
        //System.out.println(UIInternational.chan);    }
}现在问题是,比如现在我的窗口是中文界面,我想切换到英文界面时,我只要调用一下UIInternational.change(en,en),这样Local可以转变过来,但界面上没有反应,我想是不是要重新刷新一下JFrame?如果是,这个怎么刷新?

解决方案 »

  1.   

    TO:yuzl32(Hello!有酒醉)
    你的方法我试过,我是在点击转换BUTTON时,如下:public void chButtion_mouseClicked(MouseEvent e) {
               UIInternational.change("zh","cn");           
               validate();
    }public void enButtion_mouseClicked(MouseEvent e) {
               UIInternational.change("en","en");
               validate();
               }可还是没有反应,........各位大哥,请明示..
      

  2.   

    应该和转换界面风格是一样的,你可以参考下SDK下的例子
      

  3.   

    放到Panel中,然后Panel有一个repaint()方法不可以么?
      

  4.   

    MARK我的方法是把界面中设置文字的地方单独做到一类方法中,更换语言的时候从新执行下这个方法。
      

  5.   

    componentToSwitch是mainFrame.getContent()      SwingUtilities.updateComponentTreeUI(componentToSwitch);
          componentToSwitch.invalidate();
          componentToSwitch.validate();
          componentToSwitch.repaint();