I’m trying to modify the following globally defined variable:
static int players;
from the following method:
public static void selectPlayers() {
JButton player1 = new JButton("1 Player");
player1.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent arg0) {
players = 1;
}
});
}
This has no effect on the variable. The variable is global so that it can be accessed from the main method. What is the best way to go about modifying the variable?
If i’m not wrong, players is an attribut not a method. and accesing a static attribut have to be through the name of his class