java - Changing language of a JComboBox -


so i'm writing program have change language different language have part done can't seem jcombobox change language example if user clicks japanese languages in jcombobox change english eigo , french furansugo there piece of code , go in actionperformed have languages?

you don't need here's code:

    /**      *       */     package gui;      import javax.swing.*;      import gui.gui;      import java.awt.*;     import java.awt.event.actionevent;     import java.awt.event.actionlistener;     import java.util.locale;     import java.util.resourcebundle;      /**      * @author michelle      *       */     public class gui extends jframe implements actionlistener {         resourcebundle res, res1, res2;         jframe frame;         jbutton button, button1, button2, button3, button4;         jlabel label, label1,label2,label3, label4;         jscrollpane output;         jcombobox<string> combo;         string[] array;          public gui()         {                    locale loc = new locale("fr"); //create locale french in france          res = res.getbundle("programresource.programresource_fr",loc); //create resource bundle         res1 = res1.getbundle("programresource.programresource_jp",loc);         res2 = res2.getbundle("programresource.programresource_en",loc);              container c = getcontentpane();             jpanel p = new jpanel();             string[] array = {"english", "french", "japanese"};             combo = new jcombobox<string>(array);             output = new jscrollpane(combo);             combo.addactionlistener(this);              jmenubar mb = new jmenubar();              mb.add(output);              setjmenubar(mb);              label = new jlabel();             label1 = new jlabel();             label2= new jlabel();             label3 = new jlabel();             label4 = new jlabel();              imageicon apple = new imageicon("apple.jpg");             label.seticon(apple);             button = new jbutton("apple");             button.addactionlistener(this);              imageicon banana = new imageicon("banana.jpg");             label1.seticon(banana);             button1 = new jbutton("banana");             button1.addactionlistener(this);              imageicon grapes = new imageicon("grapes.jpg");             label2.seticon(grapes);             button2 = new jbutton("grapes");             button2.addactionlistener(this);              imageicon orange = new imageicon("orange.jpg");             label3.seticon(orange);             button3 = new jbutton("orange");             button3.addactionlistener(this);              imageicon pear = new imageicon("pear.jpg");             label4.seticon(pear);             button4 = new jbutton("pear");             button4.addactionlistener(this);              p.add(label);             p.add(label1);             p.add(label2);             p.add(label3);             p.add(label4);             p.add(button);             p.add(button1);             p.add(button2);             p.add(button3);             p.add(button4);             c.add(p);              setsize(425,300);             setvisible(true);         }          //french         public void actionperformed(actionevent a) {             button(a);             button1(a);             button2(a);             button3(a);             button4(a);              }      public void button(actionevent a) {         if (a.getsource() instanceof jcombobox) {             // todo auto-generated method stub         jcombobox ref = (jcombobox)a.getsource();              if(ref.getselecteditem().equals("french"))             {                 button.settext(res.getstring("computebutton"));             }             else if(ref.getselecteditem().equals("japanese"))             {                 button.settext(res1.getstring("computebutton1_jp"));             }             else if(ref.getselecteditem().equals("english"))             {                 button.settext(res2.getstring("computebutton_en"));             }         }     }      public void button1(actionevent a) {         if (a.getsource() instanceof jcombobox) {             // todo auto-generated method stub         jcombobox ref = (jcombobox)a.getsource();              if(ref.getselecteditem().equals("french"))             {                 button1.settext(res.getstring("computebutton1"));             }             else if(ref.getselecteditem().equals("japanese"))             {                 button1.settext(res1.getstring("computebutton1_jp"));             }             else if(ref.getselecteditem().equals("english"))             {                 button1.settext(res2.getstring("computebutton1_en"));             }         }     }      public void button2(actionevent a) {         if (a.getsource() instanceof jcombobox) {             // todo auto-generated method stub         jcombobox ref = (jcombobox)a.getsource();              if(ref.getselecteditem().equals("french"))             {                 button2.settext(res.getstring("computebutton2"));             }              else if(ref.getselecteditem().equals("japanese"))             {                 button2.settext(res1.getstring("computebutton2_jp"));             }             else if(ref.getselecteditem().equals("english"))             {                 button2.settext(res2.getstring("computebutton2_en"));             }         }     }      public void button3(actionevent a) {         if (a.getsource() instanceof jcombobox) {             // todo auto-generated method stub         jcombobox ref = (jcombobox)a.getsource();              if(ref.getselecteditem().equals("french"))             {                 button3.settext(res.getstring("computebutton3"));             }             else if(ref.getselecteditem().equals("japanese"))             {                 button3.settext(res1.getstring("computebutton3_jp"));             }             else if(ref.getselecteditem().equals("english"))             {                 button3.settext(res2.getstring("computebutton3_en"));             }         }     }      public void button4(actionevent a) {         if (a.getsource() instanceof jcombobox) {             // todo auto-generated method stub         jcombobox ref = (jcombobox)a.getsource();              if(ref.getselecteditem().equals("french"))             {                 button4.settext(res.getstring("computebutton4"));             }              else if(ref.getselecteditem().equals("japanese"))             {                 button4.settext(res1.getstring("computebutton4_jp"));             }             else if(ref.getselecteditem().equals("english"))             {                 button4.settext(res2.getstring("computebutton4_en"));             }         }     }      public static void main(string[] args) {         // todo auto-generated method stub         gui gui = new gui();         gui.setdefaultcloseoperation(jframe.exit_on_close);     }     } 

i try example defining listener help. don't understand why have 3 instances of bundles... should have 1 according desired language..

    button button1 = new button();     button1.setcaption(resourcebundle.getbundle("yourfile",your_locale).getlabel("fruit.banana"));     button1.seticon(commonicons.add);     button1.addlistener(new clicklistener()     {         private static final long serialversionuid = 7855693595481663167l;          @override         public void buttonclick(clickevent event)         {             handleaddbutton();         }     }); 

i think should ok that. suggest make array of jpgs , array of jbutton... , initialize them in loop. way manage n objects , not duplicate code messy...


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -