pI have a pop up menu that appears whenever I right click and a huge amount of buttons.
When the popup menu appears I have the numbers 1 - 9.
My goal is that when I click on a number, the buttons name changes to whatever number I clicked on.
My problem right now is that I just can't get the proper number, I can only make something happen when it's clicked.
public class InputListener implements MouseListener{
public void mousePressed(MouseEvent e){
((JButton)e.getSource()).setText(((JMenuItem)e.getSource()).getText());
}
}
this is the basic listener I want to add. getSource seems to get the button, since whenever I click i get a can't cast Button to MenuItem error.
Can anyone help? How should I get the proper values to work with?
Previously I tried an anonymouse array, I just looped for each button, but the variable "a" that I used had to be final which defeated the purpose, and making it (ActionEvent e, int a) didn't work as well.
After I get this listener to work, I guess I just loop and add it to each button?
When the popup menu appears I have the numbers 1 - 9.
My goal is that when I click on a number, the buttons name changes to whatever number I clicked on.
My problem right now is that I just can't get the proper number, I can only make something happen when it's clicked.
public class InputListener implements MouseListener{
public void mousePressed(MouseEvent e){
((JButton)e.getSource()).setText(((JMenuItem)e.getSource()).getText());
}
}
this is the basic listener I want to add. getSource seems to get the button, since whenever I click i get a can't cast Button to MenuItem error.
Can anyone help? How should I get the proper values to work with?
Previously I tried an anonymouse array, I just looped for each button, but the variable "a" that I used had to be final which defeated the purpose, and making it (ActionEvent e, int a) didn't work as well.
After I get this listener to work, I guess I just loop and add it to each button?