How can I add a seperate action listener to all 14 of my buttons at once that can determine player turn?(java) -
I have a big code, for a game I'm calling Tommy's Kumamak. I know that this is not beautiful, but I am very naive and for some reasons I know from using arrays, anyway, my problem is that I can not add a variable outside the listener and within the action listener I can modify the variable (pTurn ++) from
How can I go about adding a count to that variable from inside the action listener?
1 error was found: file: c: \ user \ public \ togiz_kumalak.java [line: 130] error: local variables pTurn is accessed from within internal class; Need to be declared final
int pTurn = 0; Button1.addActionListener {new zero-action action (action event e) {pTurn ++; if (pTurn% 2 == 0) {display.append ("\ n Player 2 cup 1");} If ( PTurn% 2! = 0) {display.append ("\ nPlayer 1Cup 1")}}); In that case, move the contents of the functionalities into orbit and then call the action For example, display the method from:
Private Zero Button Press {pTurn ++; If (pTurn% 2 == 0) {display.append ("\ n Player 2 Cup 1"); } If you (pTurn% 2! = 0) {display.append ("\ n Player 1 cup 1")}}} Then the methodology in your action: < Pre> button1.addActionListener (New Executioner) {Public Zero Action Action (Action Event e) {OuterClass.this.buttonPressed ();}}); Where external class is the name of your class.
Comments
Post a Comment