//Author: ^-^Veerle^-^ import java.awt.Color; import java.awt.event.ActionListener; import javax.swing.JMenuBar; import javax.swing.JMenu; import javax.swing.JMenuItem; public class calcMenu extends JMenuBar { private final String[] strActionCommands = {"English", "Dutch", "Spanish"}; private final String[] strEnglishLanguage = {"English", "Dutch (Christel Vetjens)", "Spanish (Juliana Zafra)"}; private final String[] strDutchLanguage = {"Engels", "Nederlands (Christel Vetjens)", "Spaans (Juliana Zafra)"}; private final String[] strSpanishLanguage = {"Ingles", "Holandes (Christel Vetjens)", "Espanol (Juliana Zafra)"}; private JMenuItem[] mItems = new JMenuItem[strActionCommands.length]; public calcMenu (ActionListener mainApp) { this(mainApp, new Color(255, 255, 255), new Color(0, 0, 0)); //If only an ActionListener was passed, call the main constructor along with the default colours } public calcMenu (ActionListener mainApp, Color clrMenuBackground, Color clrMenuForeground) { JMenu menuLanguage = new JMenu("Language"); for (int i = 0; i < mItems.length; i++) { mItems[i] = new JMenuItem(); mItems[i].setActionCommand(strActionCommands[i]); mItems[i].addActionListener(mainApp); mItems[i].setBackground(clrMenuBackground); mItems[i].setForeground(clrMenuForeground); menuLanguage.add(mItems[i]); } this.add(menuLanguage); this.setBackground(clrMenuBackground); menuLanguage.setBackground(clrMenuBackground); menuLanguage.setForeground(clrMenuForeground); } public void setLanguage (String strLanguage) { for (int i = 0; i < mItems.length; i++) { if (strLanguage.equalsIgnoreCase("Dutch")) { mItems[i].setText(strDutchLanguage[i]); } else if (strLanguage.equalsIgnoreCase("Spanish")) { mItems[i].setText(strSpanishLanguage[i]); } else { mItems[i].setText(strEnglishLanguage[i]); } } } }