-
Internationalization: select language of menu
Hi, I'm trying to make the user select the language of a very simple menu.
I post here the 2 classes: Menus and Selector.
In the Menus class, there are 2 items: File and Help
When you click on File then you select Configuration, and it shows the Selector class which is only a ComboBox, where you select the Language.
The Menus class is in part internationalized because I defined a Resources.properties file with this pairs:
TITLE=Internationalization!
FILE=File
HELP=Help
OPEN=Open
CONFIGURATION=Configuration
So that's first step is done, and it works fine, now I need the end user to select the language in the Configuration combo box and on the fly load TITLE, FILE,HELP,OPEN and CONFIGIRATION from an appropiate Resourses_es_ESP.properties file that I've already created, if for example he selects Spanish, that properties file has this pairs:
TITLE=Internationacionalizacion
FILE=Archivo
HELP= Ayuda
OPEN=Abrir
CONFIGURATION=Configuracion.
Any help please?
Here is the menu class just to select the Configuration option:
Code:
import java.awt.event.*;
import java.util.ResourceBundle;
public class Menus extends javax.swing.JFrame
{
ResourceBundle res = ResourceBundle.getBundle("Resources");
public Menus()
{
setSize(500, 300);
String title = res.getString("TITLE");
this.setTitle(title);
initComponents();
}
private void initComponents()
{
jmbarBarraDeMenus = new javax.swing.JMenuBar();
jmnuArchivo = new javax.swing.JMenu();
String fi = res.getString("FILE");
jmnuArchivo.setText(fi);
jmbarBarraDeMenus.add(jmnuArchivo);
jmbarBarraDeMenus.add(jmnuArchivo);
jmnuHelp = new javax.swing.JMenu();
String hel = res.getString("HELP");
jmnuHelp.setText(hel);
jmbarBarraDeMenus.add(jmnuHelp);
jmnuAbrir = new javax.swing.JMenuItem();
String op = res.getString("OPEN");
jmnuAbrir.setText(op);
jmnuArchivo.add(jmnuAbrir);
jmnuConfigura = new javax.swing.JMenuItem();
String co = res.getString("CONFIGURATION");
jmnuConfigura.setText(co);
jmnuArchivo.add(jmnuConfigura);
jmnuConfigura.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuConf_actionPerformed(e);
}
});
getContentPane().setLayout(null);
addWindowListener(new java.awt.event.WindowAdapter()
{
public void windowClosing(java.awt.event.WindowEvent evt)
{
exitForm(evt);
}
});
setJMenuBar(jmbarBarraDeMenus);
}//GEN-END:initComponents
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit (0);
}
void jMenuConf_actionPerformed(ActionEvent e) {
Selector dlg = new Selector();
dlg.setVisible(true) ;
}
public static void main (String args[])
{
new Menus().setVisible(true);
}
private javax.swing.JMenuBar jmbarBarraDeMenus;
private javax.swing.JMenu jmnuArchivo;
private javax.swing.JMenu jmnuHelp;
private javax.swing.JMenuItem jmnuAbrir;
private javax.swing.JMenuItem jmnuConfigura;
}
and here is the Selector class, just a combo box to select the language
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Selector extends javax.swing.JFrame
{
/** Creates new form CAplicación */
private javax.swing.JLabel jEtSaludo;
private javax.swing.JButton jBtSaludo;
public Selector() // constructor
{
setSize(300, 200); // tamaño del formulario
setTitle("Language Selector"); // título del formulario
initComponents(); // iniciar controles o componentes
}
private void initComponents()//GEN-BEGIN:initComponents
{
getContentPane().setLayout(null);
addWindowListener(new java.awt.event.WindowAdapter()
{
public void windowClosing(java.awt.event.WindowEvent evt)
{
exitForm(evt);
}
});
String[] langStrings = { "Spanish", "French", "Dutch", "Chinese", "English" };
JComboBox langList = new JComboBox(langStrings);
langList.setSelectedIndex(4);
getContentPane().add(langList);
langList.setBounds(42,90,204,30);
}//GEN-END:initComponents
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
System.exit (0);
}//GEN-LAST:event_exitForm
private void langListActionPerformed(java.awt.event.ActionEvent evt)
{
//do something
}
/**
* @param args the command line arguments
*/
public static void main (String args[])
{
new Selector().setVisible(true);
}
}
Similar Threads
-
By deBassMan in forum AJAX
Replies: 1
Last Post: 08-27-2007, 10:16 AM
-
By Cary R in forum Database
Replies: 24
Last Post: 09-24-2001, 02:40 PM
-
Replies: 0
Last Post: 09-05-2001, 02:24 AM
-
By Nirit Touboul in forum Database
Replies: 7
Last Post: 02-25-2001, 11:34 AM
-
By Paul R. Wilde \(vbClarity\) in forum vb.announcements
Replies: 0
Last Post: 12-01-2000, 10:25 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks