Hello there im having a little problem here, i am trying to call a random number generated in another class and display it via jlabel in 2nd class (jform) and i am sort of lost. number generating is double.
code
GaussianGenerator num = new GaussianGenerator();//calling another class
CriminalDetails()
{
initComponents();
double number = 0;
num.GaussianGenerator(number);
CriminalID.setText(Double.toString(number));//CriminalID jfield
}
The number im getting on jfield is the 0 initialized in “double number” but i want to get number generated in GaussianGenerator class.
Thank you for having a look and your time, help appreciated.
num is an instance of the number generator. You should be setting the value of number by calling a method on the instance of the number generator object and assigning it to number. Like this (I am not familiar with your other class):
Or is GaussianGenerator is also the name of the method? Bad idea from a design standpoint. Rather than passing it to the method as a paremeter, the method should just return the generated value:
numer = num.GaussianGenerator();
In Java you can’t pass a primitive by reference if that is what you are trying to do. You can do this with objects (e.g. Double), however, but that is bad design since a double will suffice. You should also read a good tutorial on Java coding conventions so you can learn how to properly name and capitalize methods. So you would see that this is better coding: