I\'m making a cookie clicker clone in java to practice my java skills and I have a small problem, I have variables that are declared in the main method that I want to access
You would have to make the variables public class variables instead of method variables, thereby increasing the scope and visiblity of the variables. Like so:
public class ActionClass {
{
public string MyPublicVariable = "woot";
@Override
public void actionPerformed(ActionEvent e) {
...
}
}
A more popular/recommended way to do this is to use a getter/setter instead of making the variable explicitly public. You would access a private variable through public methods like so:
public class ActionClass {
{
@Override
public void actionPerformed(ActionEvent e) {
private string MyPublicVariable = "woot";
public void setMyString(string newString){
MyPublicVariable = newString;
}
public string getMyString(){
return MyPublicVariable;
}
}
}
This way, you have more control over what your variables are set to.