import java.awt.GridLayout; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.ImageIcon; import javax.swing.JPanel; public class calcOppPad extends JPanel { private final String[] strOperations = {"Sq","v","+","-","*","/","%","="}; private final String[] strDutchToolTips = {"het laatste nummer in het kwadraat","wortel trekken van het laatste nummer","optellen","aftrekken","vermenigvuldigen","delen","percentage","uitrekenen"}; private final String[] strSpanishToolTips = {"Ajusta el número actual por sí mismo","Encuentre la raíz cuadrada del número incorporado","Sume dos numeros juntos","Restar el segunto numero con el primero","Multiplica dos numeros juntos","Divir el segundo numero con el primero","Porcentaje","Realice el calculo"}; private final String[] strEnglishToolTips = {"Squares the current number by itself","Find the square root of the entered number","Add two numbers together","Subtract the 2nd number from the 1st","Multiply two numbers together","Divide the 2nd number from the 1st","percentage","Perform the calculation"}; private JButton[] cmdOperationButtons = new JButton[strOperations.length]; public calcOppPad (ActionListener mainApp) { this.setLayout(new GridLayout(4,2,3,3)); for (int i = 0; i < strOperations.length; i++) { cmdOperationButtons[i] = new JButton(strOperations[i]); cmdOperationButtons[i].addActionListener(mainApp); if (strOperations[i].equalsIgnoreCase("Sq")) { cmdOperationButtons[i].setActionCommand("^"); } else if (strOperations[i].equalsIgnoreCase("v")) { cmdOperationButtons[i].setActionCommand("v"); } this.add(cmdOperationButtons[i]); } } public void setupImages (ImageIcon[] imgIcon, String[] strKeys) { int keysFound = 0; for (int i = 0, keyIndex = 0; i < strOperations.length; i++) { for (int k = 0; k < strKeys.length; k++) //Check each button for all the keys { if (strOperations[i].equalsIgnoreCase(strKeys[k])) //If a key matches { cmdOperationButtons[i].setText(""); cmdOperationButtons[i].setIcon(imgIcon[k]); keysFound++; break; //No need to loop since the key has been found for the button } } if (keysFound == strKeys.length) //If all keys have been found, no point looping anymore { break; } } } public void setLanguage (String strLanguage) { for (int i = 0; i < strOperations.length; i++) { if (strLanguage.equalsIgnoreCase("Dutch")) { cmdOperationButtons[i].setToolTipText(strDutchToolTips[i]); } else if (strLanguage.equalsIgnoreCase("Spanish")) { cmdOperationButtons[i].setToolTipText(strSpanishToolTips[i]); } else { cmdOperationButtons[i].setToolTipText(strEnglishToolTips[i]); } } } }