I'm trying to make a JTextField receive an array of numbers. I tryed with "for" and all the stuff needed to run an array, but without succes. Here is the piece of code.
private void cbxGeraValorActionPerformed(java.awt.event.ActionEvent evt)
{
if(cbxRandom.isSelected())
{
double[] num = new double[10];
for(int i=0; i<10; i++)
{
Random r = new Random();
num[i] = r.rnd;
txtValor.setText(String.valueOf(num[i]));
}
}
if(cbxRandom.isSelected())
{
double[] num = new double[10];
String newtxt = "";
for(int i=0; i<10; i++)
{
Random r = new Random();
num[i] = r.rnd;
newtxt += String.valueOf(num[i]);
}
txtValor.setText(newtxt); //do setting only after the loop ends
}
if(cbxRandom.isSelected())
{
double[] num = new double[10];
String newtxt = "";
for(int i=0; i<10; i++)
{
Random r = new Random();
num[i] = r.rnd;
newtxt += String.valueOf(num[i]) + " "; // Separate numbers
}
txtValor.setText(newtxt); //do setting only after the loop ends
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With