469,352 Members | 1,646 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

Change language of menu

19
Hi! I'm trying to let the end-user select the language of the menues I'm showing him.
To do that I've got this Selector class that shows the end user a combo box, a label and a button. In the combo box the user selects the language (English,Spanish,French,..) and when he clicks in the button shows the label in the language selected.
This works fine but it's just one form, I need to change the language of all the menues in an application, so now I've got the Menus class which shows some items one of them is FILE, when you select FILE, then CONFIGURATION you are in the Selector class.
Now I need to change the items in the menu class when you change the language in the Selector. Do I have to declare all the Menus items in the Selector class to do that?
Any help will be appreciated


Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import java.util.*;
  5.  
  6. public class Selector extends javax.swing.JFrame
  7. {
  8. //private ResourceBundle resources;
  9. private javax.swing.JLabel jEtSaludo;
  10. private javax.swing.JButton jBtSaludo;
  11. private javax.swing.JComboBox langList;
  12. private javax.swing.JButton jbtAceptar;
  13. private javax.swing.JLabel jlbGradosC;
  14. public javax.swing.JMenu jmnuArchivo;  
  15.  
  16.   public Selector()      // constructor
  17.   { //loadResources();
  18.     setSize(300, 200);      // tamaño del formulario
  19.     setTitle("Language Selector"); // título del formulario
  20.     initComponents();       // iniciar controles o componentes
  21.   }
  22.  
  23.  
  24.     private void initComponents()//GEN-BEGIN:initComponents
  25.   {
  26.  
  27.    getContentPane().setLayout(null);
  28.       addWindowListener(new java.awt.event.WindowAdapter()
  29.         {
  30.           public void windowClosing(java.awt.event.WindowEvent evt)
  31.             {
  32.           exitForm(evt);
  33.             }
  34.         });
  35.  
  36.  
  37.      jlbGradosC = new javax.swing.JLabel();
  38.      jlbGradosC.setText("TestLabel");
  39.      getContentPane().add(jlbGradosC);
  40.      jlbGradosC.setBounds(12,28,116,16);
  41.  
  42.      String[] langStrings = { "Español", "French", "Dutch", "Catalan", "Ingles" };
  43.  
  44.    langList = new JComboBox(langStrings);
  45.    langList.setSelectedIndex(4);
  46.    getContentPane().add(langList);
  47.     langList.setBounds(42,90,204,30);
  48.  
  49.     jbtAceptar= new javax.swing.JButton();
  50.     jbtAceptar.setText("Aceptar");
  51.     getContentPane().add(jbtAceptar);
  52.     jbtAceptar.setBounds(195,20,85,26);
  53.    jbtAceptar.addActionListener(new java.awt.event.ActionListener()
  54.     {
  55.       public void actionPerformed(java.awt.event.ActionEvent evt)
  56.       {
  57.         jbtAceptarActionPerformed(evt);
  58.       }
  59.     });
  60.  
  61.   }//GEN-END:initComponents
  62.  
  63.  
  64. private void jbtAceptarActionPerformed(java.awt.event.ActionEvent evt)
  65.  {
  66.  
  67.   Object nombre;
  68.   nombre = langList.getSelectedItem();
  69.  
  70.         System.out.println("Language--> " + nombre);
  71.         if(nombre.equals("Ingles")){
  72.             Locale localizacion = Locale.US;  //en inglés
  73.             ResourceBundle mensajes = ResourceBundle.getBundle("Datos",localizacion);      
  74.             jlbGradosC.setText(mensajes.getString("Etiquetaprueba"));
  75.  
  76.  
  77. }
  78.  
  79. else if(nombre.equals("Español")){
  80.             Locale localizacion2;
  81.            localizacion2 = new Locale("es", "ES");
  82.             ResourceBundle mensajes = ResourceBundle.getBundle("Datos",localizacion2);      
  83.            jlbGradosC.setText(mensajes.getString("Etiquetaprueba"));
  84.  
  85.  
  86.  }
  87.  
  88. else if(nombre.equals("Catalan")){
  89.             Locale localizacion3;
  90.            localizacion3 = new Locale("ca", "ES");
  91.             ResourceBundle mensajes = ResourceBundle.getBundle("Datos",localizacion3);      
  92.            jlbGradosC.setText(mensajes.getString("Etiquetaprueba"));
  93.  
  94.  
  95.                  }
  96.  
  97.  
  98.  
  99. }  
  100.  
  101.  
  102.   /** Exit the Application */
  103.   private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
  104.     System.exit (0);
  105.   }//GEN-LAST:event_exitForm
  106.  
  107.  
  108.  
  109.  
  110.  
  111.   public static void main (String args[])
  112.   {
  113.     new Selector().setVisible(true);
  114.   }
  115.  
  116.  
  117. }

Expand|Select|Wrap|Line Numbers
  1. import java.awt.event.*; 
  2. import java.util.ResourceBundle; 
  3.  
  4.  
  5. public class Menus extends javax.swing.JFrame 
  6. //ResourceBundle res = ResourceBundle.getBundle("Resources"); 
  7.  
  8.  
  9. public Menus() 
  10. setSize(500, 300); 
  11. //String title = res.getString("TITLE"); 
  12. this.setTitle("APPLICATION TITLE"); 
  13. initComponents(); 
  14.  
  15.  
  16. private void initComponents() 
  17. jmbarBarraDeMenus = new javax.swing.JMenuBar(); 
  18.  
  19. jmnuArchivo = new javax.swing.JMenu(); 
  20. String fi = res.getString("FILE"); 
  21. jmnuArchivo.setText("FILE"); 
  22. //jmbarBarraDeMenus.add(jmnuArchivo); 
  23.  
  24.  
  25. jmnuHelp = new javax.swing.JMenu(); 
  26. //String hel = res.getString("HELP"); 
  27. jmnuHelp.setText("HELP"); 
  28. jmbarBarraDeMenus.add(jmnuHelp);
  29.  
  30. jmnuLang = new javax.swing.JMenu(); 
  31. //String lang = res.getString("LANGUAGE"); 
  32. jmnuLang.setText("ABOUT"); 
  33. jmbarBarraDeMenus.add(jmnuLang);
  34.  
  35.  
  36.  
  37. jmnuAbrir = new javax.swing.JMenuItem(); 
  38. //String op = res.getString("OPEN"); 
  39. jmnuAbrir.setText("OPEN"); 
  40.  
  41.  
  42. jmnuArchivo.add(jmnuAbrir); 
  43.  
  44.  
  45. jmnuConfigura = new javax.swing.JMenuItem(); 
  46. //String co = res.getString("CONFIGURATION"); 
  47. jmnuConfigura.setText("CONFIGURATION"); 
  48. jmnuArchivo.add(jmnuConfigura); 
  49. jmnuConfigura.addActionListener(new ActionListener() { 
  50. public void actionPerformed(ActionEvent e) { 
  51. jMenuConf_actionPerformed(e); 
  52. }); 
  53.  
  54.  
  55.  
  56. getContentPane().setLayout(null); 
  57. addWindowListener(new java.awt.event.WindowAdapter() 
  58. public void windowClosing(java.awt.event.WindowEvent evt) 
  59. exitForm(evt); 
  60. }); 
  61. setJMenuBar(jmbarBarraDeMenus); 
  62. }//GEN-END:initComponents 
  63.  
  64. /** Exit the Application */ 
  65. private void exitForm(java.awt.event.WindowEvent evt) { 
  66. System.exit (0); 
  67.  
  68.  
  69. void jMenuConf_actionPerformed(ActionEvent e) { 
  70. Selector dlg = new Selector(); 
  71. dlg.setVisible(true) ; 
  72.  
  73.  
  74. public static void main (String args[]) 
  75. new Menus().setVisible(true); 
  76.  
  77. private javax.swing.JMenuBar jmbarBarraDeMenus; 
  78. public javax.swing.JMenu jmnuArchivo; 
  79. private javax.swing.JMenu jmnuHelp; 
  80. private javax.swing.JMenu jmnuLang;
  81. private javax.swing.JMenuItem jmnuAbrir; 
  82. private javax.swing.JMenuItem jmnuConfigura; 
  83.  
Aug 20 '07 #1
9 8961
praveen2gupta
201 100+
Hi
A i got your point is that you wants the menu and menu bar should be displayed on the basis of language selected by the user.

Since the text are fixed and we set them using a method ( jmnuLang.setText("ABOUT"); ). In the above case you should set the labels of the menu on the basis of selection of language you can try use if -else if statement or switch statement and then place the labels on the respective language.
Aug 21 '07 #2
JosAH
11,448 Expert 8TB
Hi
A i got your point is that you wants the menu and menu bar should be displayed on the basis of language selected by the user.

Since the text are fixed and we set them using a method ( jmnuLang.setText("ABOUT"); ). In the above case you should set the labels of the menu on the basis of selection of language you can try use if -else if statement or switch statement and then place the labels on the respective language.
No, that's not the way to go: as soon as another language needs to be supported
the if statements or switch statements in all the 'localizable' components need
to be changed and augmented.

Better turn those components to observers (or listeners) and as soon as a language
changes the observers must be notified (the Localizer object should therefor be
an observable).

The observers pass the I18N key to the Localizer and receive their new localized
text. A bit of bookkeeping takes care of the rest.

kind regards,

Jos
Aug 21 '07 #3
aleplgr
19
Yes, now I have the listener which is the Selector class I post here.
It works fine but there's a problem I can't solve:
I have a Menus class which is only a menu with 3 items: File,Help and Descriptive. when you select the File item there is the Configuration item where there is a combo box to select the language, when you select a language and click the button it changes the language of the File,Help and Descriptive items, that works fine.
But now in the Descriptive item there's the Test item where when you click it I'm trying to display another panel (the last one I post here) with 2 labels and a button that I need to also change when you select a language in the Configuration panel but it's not working, I think that the problem is at the end of class Menus, in this method the message "hello I'm hereeeeee" is printed butthe conv panel is never created

Expand|Select|Wrap|Line Numbers
  1. private void jMenuUniva_actionPerformed(ActionEvent e)
  2.    {
  3.        System.out.println("hello I'm hereeeeee");
  4.      Conver conv = new Conver(this);
  5.       res = ResourceBundle.getBundle("Resources");
  6.       updateStrings();
  7.  
  8.    }




Expand|Select|Wrap|Line Numbers
  1. import java.awt.event.*;
  2. import java.util.*;
  3. import javax.swing.*;
  4.  
  5. public class Menus extends JFrame
  6. {
  7.    public ResourceBundle res;
  8.    private JMenuBar jmbarBarraDeMenus;
  9.    private JMenu jmnuArchivo;
  10.    private JMenu jmnuHelp;
  11.     private JMenu jmnuDescriptiva;//agregué
  12.    private JMenuItem jmnuAbrir;
  13.    private JMenuItem jmnuConfigura;
  14.     private JMenuItem jmnuUniva;//agregué
  15.  
  16.         //private javax.swing.JLabel jlbGradosC;
  17.  
  18.    public Menus()
  19.    {
  20.       Locale.setDefault(new Locale("en")); //Inglés
  21.       res = ResourceBundle.getBundle("Resources");
  22.       setSize(500, 300);
  23.       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  24.       initComponents();
  25.       updateStrings();
  26.       setVisible(true);
  27.    }
  28.  
  29.    private void initComponents()
  30.    {
  31.       jmbarBarraDeMenus = new javax.swing.JMenuBar();
  32.       jmnuArchivo = new javax.swing.JMenu();
  33.         jmnuDescriptiva = new javax.swing.JMenu();//agregué 
  34.  
  35.       jmbarBarraDeMenus.add(jmnuArchivo);
  36.  
  37.       jmnuHelp = new javax.swing.JMenu();
  38.       jmbarBarraDeMenus.add(jmnuHelp);
  39.         jmbarBarraDeMenus.add(jmnuDescriptiva);
  40.  
  41.       jmnuAbrir = new javax.swing.JMenuItem();
  42.       jmnuArchivo.add(jmnuAbrir);
  43.       jmnuConfigura = new javax.swing.JMenuItem();
  44.       jmnuArchivo.add(jmnuConfigura);
  45.  
  46.         jmnuUniva = new javax.swing.JMenuItem();//agregue    
  47.       jmnuDescriptiva.add(jmnuUniva);//agregué
  48.  
  49.  
  50.         // jlbGradosC = new javax.swing.JLabel();
  51.  
  52.  
  53.       jmnuConfigura.addActionListener(
  54.          new ActionListener()
  55.          {
  56.             public void actionPerformed(ActionEvent e)
  57.             {
  58.                jMenuConf_actionPerformed(e);
  59.             }
  60.          });
  61.      jmnuUniva.addActionListener(
  62.          new ActionListener()
  63.          {
  64.             public void actionPerformed(ActionEvent e)
  65.             {
  66.                jMenuUniva_actionPerformed(e); //agregué
  67.             }
  68.          });
  69.  
  70.  
  71.  
  72.  
  73.  
  74.        getContentPane().setLayout(null);
  75.       setJMenuBar(jmbarBarraDeMenus);
  76.    }
  77.  
  78.  
  79.  
  80.  
  81.  
  82.    private void updateStrings()
  83.    {
  84.       setTitle(res.getString("TITLE"));
  85.       jmnuArchivo.setText(res.getString("FILE"));
  86.       jmnuHelp.setText(res.getString("HELP"));
  87.       jmnuAbrir.setText(res.getString("OPEN"));
  88.       jmnuConfigura.setText(res.getString("CONFIGURATION"));
  89.         jmnuDescriptiva.setText(res.getString("DESCRIPTIVE"));
  90.         jmnuUniva.setText(res.getString("UNIVARIANTE"));      
  91.    }
  92.  
  93.    private void jMenuConf_actionPerformed(ActionEvent e)
  94.    {
  95.       Selector dlg = new Selector(this);
  96.       res = ResourceBundle.getBundle("Resources");
  97.       updateStrings();
  98.    }
  99.  
  100.  private void jMenuUniva_actionPerformed(ActionEvent e)//Agregué esto
  101.    {
  102.        System.out.println("hello I'm hereeeeee");
  103.      Conver conv = new Conver(this);
  104.       res = ResourceBundle.getBundle("Resources");
  105.       updateStrings();
  106.  
  107.  
  108.    }
  109.  
  110.  
  111.  
  112.    public static void main(String args[])
  113.    {
  114.       new Menus();
  115.    }
  116. }


The Selector class

public class Selector extends JDialog implements ActionListener
{
private final static String[] LANG_STRINGS = { "Spanish", "French", "Dutch", "Chinese", "English" };
private final static String[] LOCALES = { "es", "fr", "nl", "cn", "en"};
private static int lastIndex = 4;
private JComboBox langList;
private JButton OKButton;

public Selector(JFrame owner)
{
super(owner, true);
setSize(300, 200);
setTitle("Language Selector");
initComponents();
setVisible(true);
}

private void initComponents()
{
getContentPane().setLayout(null);
addWindowListener(
new java.awt.event.WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
dispose();
}
});
langList = new JComboBox(LANG_STRINGS);
langList.setSelectedIndex(lastIndex);
langList.setBounds(42, 50, 204, 30);
getContentPane().add(langList);
OKButton = new JButton("OK");
OKButton.setBounds(90, 110, 100, 30);
OKButton.setActionCommand("seleccionar");
OKButton.addActionListener(this);
getContentPane().add(OKButton);
}

public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("seleccionar"))
{
lastIndex = langList.getSelectedIndex();
Locale.setDefault(new Locale(LOCALES[lastIndex]));
dispose();
}
}

public static void main(String args[])
{
new Selector(null);
}
}



dfsg

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


public class Conver extends JFrame
{
/**Crear un nuevo formulario Conver*/
public Conver(JFrame owner)
{
setSize(500,200);//tamaño del formulario
setTitle("Conversion de temperaturas");//titulo del formulario
initComponents();//iniciar componenetes
}

/** El siguiente metodo es llamado por el constructorpara iniciar el formulario**/
private void initComponents()
{
//Crear los objetos
jlbGradosC = new javax.swing.JLabel();
jtfGradosC = new javax.swing.JTextField();
jlbGradosF = new javax.swing.JLabel();
jtfGradosF = new javax.swing.JTextField();
jbtAceptar = new javax.swing.JButton();

getContentPane().setLayout(null);
addWindowListener(new java.awt.event.WindowAdapter()
{
public void windowClosing(java.awt.event.WindowEvent evt)
{
exitForm(evt);
}
}
);
//Etiqueta "Grados centigrados"
jlbGradosC.setText("Grados Centigrados");
getContentPane().add(jlbGradosC);
jlbGradosC.setBounds(12,28,116,16);

//Caja de texto para los grados centigrados
jtfGradosC.setText("0.00");
jtfGradosC.setHorizontalAlignment(javax.swing.Swin gConstants.RIGHT);
getContentPane().add(jtfGradosC);
jtfGradosC.setBounds(132,28,144,20);

//Etiqueta "Grados Fahrenheit"
jlbGradosF.setText("Grados fahrenheit");
getContentPane().add(jlbGradosF);
jlbGradosF.setBounds(12,68,104,24);

//Caja de texto para los grados fahreneit
jtfGradosF.setText("32.00");
jtfGradosF.setHorizontalAlignment(javax.swing.Swin gConstants.RIGHT);
getContentPane().add(jtfGradosF);
jtfGradosF.setBounds(132,72,144,20);

//Boton Aceptar
jbtAceptar.setText("Aceptar");
jbtAceptar.setMnemonic('A');
getRootPane().setDefaultButton(jbtAceptar);
getContentPane().add(jbtAceptar);
jbtAceptar.setBounds(132,120,144,24);


java.awt.event.KeyAdapter kl=
new java.awt.event.KeyAdapter()
{
public void keyTyped(java.awt.event.KeyEvent evt)
{
// jtfGradosKeyTyped(evt);
}
};
jtfGradosC.addKeyListener(kl);
jtfGradosF.addKeyListener(kl);


}


/**Salir de la aplicacion*/
private void exitForm(java.awt.event.WindowEvent evt)
{
System.exit(0);
}

/**
*parametro args: argumentos en linea de ordenes
*/
public static void main(String args[])
{
try
{
//Aspecto de la interfaz grafica
javax.swing.UIManager.setLookAndFeel(
javax.swing.UIManager.getSystemLookAndFeelClassNam e());
}
catch (Exception e)
{
System.out.println("No se pudo establecer el aspecto deseado: " + e);
}
new Conver(null).setVisible(true);
}


private javax.swing.JLabel jlbGradosC;
private javax.swing.JTextField jtfGradosC;
private javax.swing.JButton jbtAceptar;
private javax.swing.JLabel jlbGradosF;
private javax.swing.JTextField jtfGradosF;
}
Aug 28 '07 #4
JosAH
11,448 Expert 8TB
The way you're trying to accomplish this is not the 'Swing way' of doing things.
Swing uses 'bound properties', i.e. when such a property changes it notifies
everything that is interested in the property value change.

Central in you localization framework should be a 'Localizer' that can localize
strings and add listeners to itself when a Locale changes (i.e. the language of
the application is changed).

Any component that is interested in a Locale change should register itself to
that Localizer. The trouble with Swing components is that they don't exist during
the lifetime of the application (think of buttons in a dialog or the dialog itself).

Therefore, a simple solution would be a, say 'LocalizerDelegate' that registers
itself at the Localizer and changes the text for a Swing component whenever a
Locale changes. The Swing component refers to such a LocalizerDelegate.

If the Localizer itself keeps those interested LocalizerDelegates in a WeakHashMap,
they will be automatically removed from that map whenever the Swing component
becomes out of scope and is a (potential) prey for the Garbage Collector.

A LocalizerHelper should know about *what* key to translate (or localize) for
the component (or part thereof) it is the delegate for. Whenever the Locale
changes, it is notified by the Localizer, the LocalizerDelegate consults the
Localizer again and sets the text in the Swing component that had delegated
that functionality.

The easiest approach is to subclass all Swing components that implement the
functionality outlined above. It seems like a lot of work (and it is) but it pays back
big times (believe me, I did just that some time ago ;-)

kind regards,

Jos
Aug 28 '07 #5
aleplgr
19
Thanks really for your time, but this looks too much for me, I'm absolutelly newbie.. is there please any example? the only one I could find is this one
http://www.demo2s.com/Code/Java/Development-Class/BigDemoforI18N.htm
and it uses the if else if approach...
Aug 28 '07 #6
JosAH
11,448 Expert 8TB
Thanks really for your time, but this looks too much for me, I'm absolutelly newbie.. is there please any example? the only one I could find is this one
http://www.demo2s.com/Code/Java/Development-Class/BigDemoforI18N.htm
and it uses the if else if approach...
I'm sorry for saying so but that example sucks big times. That way is not the
way to go for I18N and L10N. Especially not if you want to change the Locale
(language) while the application is running. Don't use it. To do it properly takes
a lot more work and I don't even know if the way I did it is the 'best' way to do it.

Maybe I should write a little article series about it; I don't know yet, but most
certainly your question cannot be answered in a single reply; sorry 'bout that.

kind regards,

Jos
Aug 28 '07 #7
r035198x
13,262 8TB
Thanks really for your time, but this looks too much for me, I'm absolutelly newbie.. is there please any example? the only one I could find is this one
http://www.demo2s.com/Code/Java/Development-Class/BigDemoforI18N.htm
and it uses the if else if approach...
I don't think choosing an inferior alternative approach is the way to go here. If you're a "newbie" (I like to call it leaners because everyone is a learner) then doing this as Jos suggested will make you a learn a lot which I think is the whole point anyway.
Aug 28 '07 #8
aleplgr
19
I found a solution (I know it sucks! and it's 100000 miles away from JosAH's ) It consists of declaring the ResourceBundle variable also in the Conver panel (this is just an example panel to see how to change its labels) and in the init components method call the getBundle and the getSring in the setText of each label and button.
I think that this is working... could I try this one while find something better?




Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2.  
  3.  
  4. public class Conver extends  JFrame
  5. {
  6. /**Crear un nuevo formulario Conver*/
  7. private  ResourceBundle res;
  8.  public Conver(JFrame owner)
  9.  { 
  10.  //super(owner, true);
  11.   setSize(500,200);//tamaño del formulario
  12.   setTitle("Conversion de temperaturas");//titulo del formulario
  13.   initComponents();//iniciar componenetes
  14.    setVisible(true);
  15.  }
  16.  
  17. /** El siguiente metodo es llamado por el constructorpara iniciar el formulario**/
  18.  private void initComponents()
  19.  {
  20.   //Crear los objetos
  21.   jlbGradosC = new javax.swing.JLabel();
  22.   jtfGradosC = new javax.swing.JTextField();
  23.   jlbGradosF = new javax.swing.JLabel();
  24.   jtfGradosF = new javax.swing.JTextField();
  25.   jbtAceptar = new javax.swing.JButton();
  26.   res = ResourceBundle.getBundle("Resources");
  27.   getContentPane().setLayout(null);
  28.   addWindowListener(new java.awt.event.WindowAdapter()
  29.    {
  30.     public void windowClosing(java.awt.event.WindowEvent evt)
  31.     {
  32.      //exitForm(evt);
  33.       dispose();
  34.    }
  35.   }
  36.   );
  37.   //Etiqueta "Grados centigrados"
  38.   jlbGradosC.setText(res.getString("GradosCentigrados"));
  39.   getContentPane().add(jlbGradosC);
  40.   jlbGradosC.setBounds(12,28,116,16);
  41.  
  42.   //Caja de texto para los grados centigrados
  43.   jtfGradosC.setText("0.00");
  44.   jtfGradosC.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
  45.   getContentPane().add(jtfGradosC);
  46.   jtfGradosC.setBounds(132,28,144,20);
  47.  
  48.   //Etiqueta "Grados Fahrenheit"
  49.   jlbGradosF.setText("Grados fahrenheit");
  50.   getContentPane().add(jlbGradosF);
  51.   jlbGradosF.setBounds(12,68,104,24);
  52.  
  53.    //Caja de texto para los grados fahreneit
  54.   jtfGradosF.setText("32.00");
  55.   jtfGradosF.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
  56.   getContentPane().add(jtfGradosF);
  57.   jtfGradosF.setBounds(132,72,144,20);
  58.  
  59.    //Boton Aceptar
  60.   jbtAceptar.setText("Aceptar");
  61.   jbtAceptar.setMnemonic('A');
  62.   getRootPane().setDefaultButton(jbtAceptar);
  63.   getContentPane().add(jbtAceptar);
  64.   jbtAceptar.setBounds(132,120,144,24);
  65.  
  66.  
  67.  java.awt.event.KeyAdapter kl=
  68.  new java.awt.event.KeyAdapter()
  69.  {
  70.  public void keyTyped(java.awt.event.KeyEvent evt)
  71.  {
  72.  // jtfGradosKeyTyped(evt);
  73.   }
  74.   };
  75.   //jtfGradosC.addKeyListener(kl);
  76.   //jtfGradosF.addKeyListener(kl); 
  77.  
  78.  
  79.  }
  80.  
  81.  
  82.  /**Salir de la aplicacion*/
  83.  private void exitForm(java.awt.event.WindowEvent evt)
  84.  {
  85.    System.exit(0);
  86.  }
  87.  
  88.  /**
  89.  *parametro args: argumentos en linea de ordenes
  90.  */
  91.  public static void main(String args[])
  92.  {
  93.    try
  94.      {
  95.       //Aspecto de la interfaz grafica
  96.       javax.swing.UIManager.setLookAndFeel(
  97.        javax.swing.UIManager.getSystemLookAndFeelClassName());
  98.     }
  99.     catch (Exception e)
  100.     {
  101.      System.out.println("No se pudo establecer el aspecto deseado: " + e);
  102.      }
  103.      new Conver(null).setVisible(true);
  104.     }
  105.  
  106.  
  107.     private javax.swing.JLabel jlbGradosC;
  108.     private javax.swing.JTextField jtfGradosC;
  109.     private javax.swing.JButton jbtAceptar;
  110.     private javax.swing.JLabel jlbGradosF;
  111.     private javax.swing.JTextField jtfGradosF;
  112.     }
  113.  
Aug 29 '07 #9
JosAH
11,448 Expert 8TB
II think that this is working... could I try this one while find something better?
Sure, why not? If it works; nobody is going to forbid you to use your current solution ;-)

kind regards,

Jos
Aug 29 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by Richard | last post: by
2 posts views Thread by RWD | last post: by
5 posts views Thread by Phil Schmidt | last post: by
4 posts views Thread by Hans Kesting | last post: by
2 posts views Thread by Steve Marshall | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.