JLabel does not receive new text

1

This code was meant to be when it clicked on the button it became invisible and lblVira became a number between 0 and 10, it gives no error message and compiles only lblVira does not "catch" the new text (I'm new to java).

private void btnstartActionPerformed(java.awt.event.ActionEvent evt) {                                         
    btnstart.setVisible(false);
    Random random = new Random();
        int array[] = new int[1]; 

        for (int i=1; i<array.length; i++) {
             array[i] = random.nextInt(10); 
            lblVira.setText(Integer.toString(array[i]));
        }    }
    
asked by anonymous 12.11.2017 / 02:15

2 answers

0
private void btnstartActionPerformed(java.awt.event.ActionEvent evt) {                                         
    btnstart.setVisible(false);
    Random random = new Random();
        int array[] = new int[1]; 

        for (int i=1; i<array.length; i++) {
             array[i] = random.nextInt(10); 
            lblVira.setText(Integer.toString(array[i]));
        }    }

Look at this for . It runs while i<1 . It happens that since it starts with i=1 , then the condition of for already starts false and it will not do anything.

I think you wanted i=0 instead of i=1 .

    
12.11.2017 / 02:24
0

I think you want something like this:

private void btnstartActionPerformed(java.awt.event.ActionEvent evt) {
    btnstart.setVisible(false);
    Random random = new Random();
    int numeroAleatorio = random.nextInt(10); 
    lblVira.setText(Integer.toString(numeroAleatorio));
}

No need to create a ArrayList

    
12.11.2017 / 02:33