1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
//mes imports
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import javax.swing.*;
public class InternationalTest extends JFrame
{
private JLabel label;
private Button French;
private Button US;
private Locale currentLocale;
private ResourceBundle res;
public InternationalTest()
{
JPanel G = new JPanel();
label = new JLabel("toto");
French = new Button("French");
US = new Button("US");
French.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
setCurrentLocale(new Locale("fr","FR"));
updateDisplay();
}
});
US.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
setCurrentLocale(new Locale("en","US"));
updateDisplay();
}
});
G.add(label);
G.add(French);
G.add(US);
Container c = this.getContentPane();
c.add(G);
setSize(200,300);
show();
}
public void setCurrentLocale(Locale locale)
{
currentLocale = locale;
res = ResourceBundle.getBundle("RetireStrings",currentLocale);
}
public void updateDisplay()
{
try{
label.setText(res.getString("Country"));
}catch( Exception e){
label.setText("pas trouvé!");
}
}
public static void main(String[] args)
{
new InternationalTest();
}
} |
Partager