Unfortunately I did not learn Java, I know other programming languages with the exception of Java.
I know how to create a Menu and add items to the menu. I figured that out from my simple basic java books. However I have access to a piece of open source software and need to make some tweaks to it, to make it work for me and I am stuck. So I will provide code of what is going on and provide code of what I have and then hopefully someone can fill in the missing pieces and explain as well as to how it worked they way it worked.
The code below is part of the file that calls TranslatorAction.java It calls it on the line when creating a new menu item. I completely understand this part. I only posted this code so you can see that the import statement is not being imported for JMenuItem and that the menu item is being added indirectly from the menu.add call. The adminMenu.add is creating the menu item by creating a object / class?? with the paremeters new TranslatorAction
javax.swing.JMenu;
import javax.swing.JMenuBar;
import com.bo.actions.TranslatorAction;
private void createAdminMenu(JMenuBar menuBar) {
JMenu adminMenu = new JMenu(com.POSConstants.ADMIN);
adminMenu.add(new TranslatorAction());
menuBar.add(adminMenu);
}
When new TranslatorAction() is called from the above for creating the new menu item. I am having an issue with accessing the setting the text for the new JMenuItem. I know from playing with the code that the line super("test"); is setting the new JMenuItem text. I want to be able to have this set to a variable, so that way it can be changed on the fly. Below is the whole file that gets called from above with adminMenu.add(New TranslatorAction());
TranslatorAction java file code
package com.bo.actions;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Icon;
import javax.swing.JTabbedPane;
import com.POSConstants;
import com.bo.ui.BackOfficeWindow;
public class TranslatorAction extends AbstractAction {
public TranslatorAction(){
//I know this sets the JMenuItem to Test. Again no importing of
//JMenuItem at all what so ever. But I need to set the JmenuItem
//to something on the fly instead of hard coding it. Can anyone
//show and explain how to dynamically create / change super("test"),
// so that way it is not hard coded?
super("Test");
}
public TranslatorAction(String name) {
super(name);
}
public TranslatorAction(String name, Icon icon) {
super(name, icon);
}
public void actionPerformed(ActionEvent e) {
}
}
Thanks for every ones' time for helping me. Shawn