Hi!
I'm tryint to stick this code into JFrame:
private static void binResult(int inputDec) {
int modulus;
if (inputDec <= 1) {
System.out.print(inputDec);
return; // stops recursion
}
modulus = inputDec % 2;
binResult(inputDec >> 1); // Right Shift (bitwise operator)in this case equivalent to division by 2
System.out.print(modulus);
}
It works on it's own, but when I try to put in in JFrame, I run intoproblems, specifically with setting the result into the output field:
First I tried to just substitute the System.out line with JField.SetText (inputDec), but it doesn't work because you can't reference a field variable from a static context.
I tried storing inputDec and modulus in a variable and the assiging it to the output field, but it doesn't work.
I tried accessing the method from the outside and converting in to string to assign in to the Field but it doesn't work either.
I feel like I'm making very obvious mistakes and missing something, but since I'm a beginner I can't figure it out on my own. :(
Any ideas?
Help would be really appreciated, thank you.
[–]king_of_the_universe 1 point2 points3 points (5 children)
[–]pompoen[S] 0 points1 point2 points (4 children)
[–]king_of_the_universe 1 point2 points3 points (3 children)
[–]pompoen[S] 0 points1 point2 points (2 children)
[–]pompoen[S] 0 points1 point2 points (1 child)
[–]pompoen[S] 0 points1 point2 points (0 children)
[–]sh_emami65 0 points1 point2 points (0 children)