Java - Sending values from Subclass -
i need sending value subclass superclass.
public class { protected int gamesize; public void setbuttons(){ for(int row = 0; row < gamesize; row++) { for(int col = 0; col < gamesize; col++) { buttons[row][col] = new playerbutton(); buttons[row][col].button.addactionlistener((actionlistener) this); buttons[row][col].player = row+""+col; buttons[row][col].button.seticon(new imageicon("src/img/empty.png")); box.add(buttons[row][col].button); } } box.setvisible(true); } } public class b extends { public void actionperformed(actionevent a) { object source = a.getsource(); jbutton pressedbutton = (jbutton)source; if(pressedbutton.gettext() == "start game") { gamesize = integer.parseint(gamesizebox.getselecteditem().tostring().replaceall("x.*","")); if((setplayername1.gettext().length() > 0) && (setplayername2.gettext().length() > 0)){ startnewgame(setplayername1.gettext(), setplayername2.gettext(), gamesize); } } if(pressedbutton.gettext() == "exit") { system.exit(0); } } }
i want able use gamesize, changed in class b, in class a. how work around problem? clarify, have variable ( gamesize ) in class protected, , change variable in class b , want "reuse" changed gamesize in forloops in class a.
thanks.
if understand, want change value in class after change in class b. after create object a:
a class_a = new a(); class_a.gamesize= /value b/
you can build constuctor in class a, set value in gamesize, , call in in class b using super() in class a
a(int a){ gamesize=a; }
and in class b
super(/* here new value */)
Comments
Post a Comment