My problem is that when I create my JFrame, it’s only setting the first String of ‘debugginState’, where later I added a ActionListener, and it’s still not updating the JFileMenuItem’s label.
Here’s the 2 pieces of code.
Code: (Majority chopped out)
public void createFrame() {
debuggingState = "Debugging: Off";
secondButtons = new String[] {debuggingState, "-", "StopWatch"};
for (String name : secondButtons) {
menuItem2 = new JMenuItem(name);
if (name.equalsIgnoreCase("-")) {
optMenu.addSeparator();
} else {
menuItem2.addActionListener(this);
optMenu.add(menuItem2);
}
}
}
And there’s a ActionListener that is bieng called (had it outprint ‘true’, if the button pressed = ignoreCase"Debugging: Off", than set the debuggingState string = “Debugging: On”;
Here’s the ActionListener:
public void actionPerformed(ActionEvent evt) {
String cmd = evt.getActionCommand();
try {
if (cmd != null) {
if (cmd.equalsIgnoreCase("Debugging: Off")) {
debuggingState = "Debugging: On";
secondButtons[0] = debuggingState;
menuItem2.setText(secondButtons[0]);
pe.debugging = true;
}
if (cmd.equalsIgnoreCase("Debugging: On")) {
debuggingState = "Debugging: Off";
secondButtons[0] = debuggingState;
menuItem2.setText(secondButtons[0]);
pe.debugging = false;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
If someone could point me in the direction on how to get that actionPerformed method to update the JFrame’s JMenuItem labels text, that would be great.
Any ideas?
^_^.