import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class I18N extends WindowAdapter 
	implements ActionListener {

	Frame frame;
	Label lab;
	Button btn;
	//采用缺省语言locale
	ResourceBundle res=ResourceBundle.getBundle("Res");
	int flag=0;
	String [][] locale={
		{"zh","CN"},
		{"en","US"},
	//	{"ja","JP"},
	};
	public void actionPerformed(ActionEvent e){
		flag=(++flag)%locale.length;
		//getBundel方法的参数决定的本地资源包的名称。
		res = ResourceBundle.getBundle("Res",
				new Locale(locale[flag][0], locale[flag][1]));
		setText();
		frame.pack();//读者可把该行注释掉，再看看程序的显示效果。
	}

	void setText(){
		lab.setText(res.getString("text1"));
		btn.setLabel(res.getString("text2"));
	}

	public void windowClosing(WindowEvent e)  {
		System.exit(0);
	}

	public I18N() throws Exception{

		frame=new Frame();
		frame.addWindowListener(this);
		lab=new Label();
		btn=new Button();
		btn.addActionListener(this);
		frame.add(lab,BorderLayout.NORTH);
		frame.add(btn,BorderLayout.CENTER);

		setText();
		frame.pack();//以紧凑的布局和组件大小来显示
		frame.setVisible(true);
	}



	public static void main(String[] args){
		try{
			new I18N();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
