private void generateActionPerformed(java.awt.event.ActionEvent evt) {
String number = getRandom(4);
int first,second,third,forth;
first = Integer.parseInt(number.substring(0,1));
second = Integer.parseInt(number.substring(1,2));
third = Integer.parseInt(number.substring(2,3));
forth = Integer.parseInt(number.substring(3));
}
private void reavealActionPerformed(java.awt.event.ActionEvent evt) {
}
so, i have for integer that i want to use it in the bottom method. Is there a way to carry(the same value) for integer first,second,third,forth into the bottom method(reavealActionPerformed) from the top method? thank you
Nope. Please read up on variable scoping in Java. (More detailed explanation of scoping - http://www.java-made-easy.com/variable-scope.html )
In short, anything declared within a method (public/private/protected), is not available outside the method. More technically, the scope of the variable is the block where it is declared, including any sub block.
If you want to share the values, think about whether they can be part of your class. If they are logically your class' attributes, you can define them as instance variables.
Or you can try returning the values in an array and call this method when you need and the values will be 'returned' from the method.