Static doesn't prevent an array from changing does it?
I'm trying to pass info from my GUI class to my Logic class using a method in my GUI:
the keyword static is required so I can use it from different classes is that right?Code:public static String[][] getStringArray(){
String[][] output = new String[9][9]
//use a loop to assign values from GUI (Grid[][].getText() to output[][])
return output;
}
The values don't seem to be changing though. My GUI consists of a Grid[9][9] of buttons, the buttons are a special extended from JButton button that has a special action mechanism:
it shows a pop up menu of values for you to choose from when you click a button.Code:public class SudokuButton extends JButton {
SudokuButton(){
addActionListener(new PopupListener());
}
class PopupListener implements ActionListener{
JPopupMenu popup = new JPopupMenu();
PopupListener(){
popup.add(new JMenuItem(new ButtonAction(" ")));
for (int a = 0; a < 9; a++){
popup.add(new JMenuItem(new ButtonAction(String.valueOf(a+1))));
}
}
public void actionPerformed(ActionEvent e) {
popup.show(getRootPane(),getX() + 45,getY() + 45);
}
}
private class ButtonAction extends AbstractAction{
private String text;
public ButtonAction(String text){
super(text);
this.text = text;
}
public void actionPerformed(ActionEvent e){
setText(text);
}
}
}
When I do so, the Grid[][].getText() should also change when I call it right? My method keeps returning the original Grid[][] instead of a new one based on user input. I had some help with this so I'm not to sure on the details. I think setText should've covered it, but I dunno, I think it's not understanding 'static' that's messing me up.
